We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.util.regex.Pattern;importjava.util.regex.Matcher;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);intn=Integer.parseInt(scanner.nextLine());//Merge all input togetherStringinput="";for(inti=0;i<n;i++)input=input+scanner.nextLine()+" ";intt=Integer.parseInt(scanner.nextLine());for(inti=0;i<t;i++){Stringuk_word=scanner.nextLine();Stringus_word=uk_word.replaceAll("our","or");Stringregex=String.format("\\b(%s|%s)\\b",uk_word,us_word);Patternpattern=Pattern.compile(regex);Matchermatcher=pattern.matcher(input);intcount=0;while(matcher.find())count++;System.out.println(count);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
UK and US: Part 2
You are viewing a single comment's thread. Return to all comments →
Java 15: