Search This Blog

Sunday, September 1, 2013

Hacker Rank Problem - Regex - Find Hackerrank

Find Hackerrank

The following is the solution to the Hacker Rank problem "Find Hackerrank". For other Hacker Rank problem solutions visit my Hacker Rank Solutions Page.

/**
 * @author Arun.G
 *
 */

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.util.Scanner;
public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
         Scanner sc = new Scanner(System.in);
        String conversation="";
        int numberOfLines=sc.nextInt();
        conversation=sc.nextLine();
        while((sc.hasNextLine()))
        {
            conversation=sc.nextLine();
            // System.out.println(conversation);
            if(conversation.startsWith("hackerrank") &&    conversation.endsWith("hackerrank"))
                System.out.println("0");
            else if(conversation.startsWith("hackerrank"))
                System.out.println("1");
            else if(conversation.endsWith("hackerrank"))
                System.out.println("2");
            else
                System.out.println("-1");
        }
       
    }
}





























No comments:

Post a Comment

Labels