You are viewing a single comment's thread. Return to all comments →
java solution
import java.io.*; import java.util.*; import java.util.regex.Pattern; import java.util.regex.Matcher; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Pattern startsWithHackerRank = Pattern.compile("^hackerrank.*"); Pattern endsWithHackerRank = Pattern.compile(".*hackerrank$"); Pattern startsAndEndsWithHackerRank = Pattern.compile("^hackerrank$"); Pattern[] patterns = {startsAndEndsWithHackerRank, startsWithHackerRank, endsWithHackerRank}; int n = Integer.parseInt(scanner.nextLine()); for (int i = 0; i < n; i++) { String string = scanner.nextLine(); int result = -1; for (int j = 0; j < patterns.length; j++) { Matcher matcher = patterns[j].matcher(string); if (matcher.matches()) { result = j; break; } } System.out.println(result); } } }
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 →
java solution