You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; 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 n = Integer.parseInt(sc.nextLine()); String[] fhr = new String[n]; for(int i=0;i<n;i++){ fhr[i] = sc.nextLine(); } Pattern pattern = Pattern.compile("hackerrank"); for(int i=0;i<n;i++){ Matcher matcher = pattern.matcher(fhr[i]); if(matcher.find()){ if(matcher.start()==0 && matcher.end()== fhr[i].length()) System.out.println("0"); else if(matcher.end()== fhr[i].length()) System.out.println("2"); else if(matcher.start()== 0) System.out.println("1"); else System.out.println("-1"); }else System.out.println("-1"); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Find HackerRank
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.util.regex.*; public class Solution {
}