Search This Blog

Sunday, September 1, 2013

Hacker Rank Problem - Regex - Saying Hi

Saying Hi

The following is the solution to the Hacker Rank problem "Saying Hi". 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.*;

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);
        int number = sc.nextInt();
        while(sc.hasNextLine())
        {
            String line = sc.nextLine();
            Pattern hiPattern = Pattern.compile("^(h|H){1}(I|i){1} [^d]");
            Matcher m = hiPattern.matcher(line);
            
            if(m.find())
                System.out.println(line);
        }
    }
}

No comments:

Post a Comment

Labels