Search This Blog

Sunday, September 1, 2013

Hacker Rank Problem - Regex - Hackerrank Language

Hackerrank Language

The following is the solution to the Hacker Rank problem " Hackerrank Language".  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(); int count=0;
        while(sc.hasNextLine())
        {
            String lines = sc.nextLine();
           
            if(!lines.equals(""))
            {
              String line[] = lines.split(" ");
           
              String pattern ="\\b(C|CPP|JAVA|PYTHON|PERL|PHP|RUBY|CSHARP"+
                "|HASKELL|CLOJURE|BASH|SCALA|ERLANG|CLISP|LUA|"+
                "BRAINFUCK|JAVASCRIPT|GO|D|OCAML|R|PASCAL|SBCL|DART|GROOVY|OBJECTIVEC)\\b";
           
              Pattern hiPattern = Pattern.compile(pattern,Pattern.CASE_INSENSITIVE);
              Matcher m = hiPattern.matcher(line[1]);
              if(m.find())
              {
                     System.out.println("VALID");
              }
              else
              {
                     System.out.println("INVALID");
              }
                                                                             
            }    
              
        }

    }
}



No comments:

Post a Comment

Labels