Search This Blog

Sunday, September 1, 2013

Hacker Rank Problem - Regex - HackerRank Tweets

HackerRank Tweets

The following is the solution to the Hacker Rank problem "HackerRank Tweets".

/**
 * @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(); int count=0;
        while(sc.hasNextLine())
        {
           String line = sc.nextLine();
           Pattern hiPattern = Pattern.compile("hackerrank",Pattern.CASE_INSENSITIVE);
           Matcher m = hiPattern.matcher(line);
           while(m.find())
           {
               count++;
           }              
        }
        System.out.println(count);
    }
}

No comments:

Post a Comment

Labels