|
| 1 | +import java.io.*; |
| 2 | +import java.math.*; |
| 3 | +import java.security.*; |
| 4 | +import java.text.*; |
| 5 | +import java.util.*; |
| 6 | +import java.util.concurrent.*; |
| 7 | +import java.util.function.*; |
| 8 | +import java.util.regex.*; |
| 9 | +import java.util.stream.*; |
| 10 | +import static java.util.stream.Collectors.joining; |
| 11 | +import static java.util.stream.Collectors.toList; |
| 12 | + |
| 13 | +class Result { |
| 14 | + |
| 15 | + |
| 16 | +public static List<Integer> matchingStrings(List<String> strings, List<String> queries) { |
| 17 | + |
| 18 | + List<Integer> result = new ArrayList<Integer>(); |
| 19 | + for (int i = 0; i < queries.size(); i++) { |
| 20 | + int count = 0; |
| 21 | + for (int j = 0; j < strings.size(); j++) { |
| 22 | + if(queries.get(i).equals(strings.get(j))){ |
| 23 | + count++; |
| 24 | + } |
| 25 | + } |
| 26 | + result.add(count); |
| 27 | + } |
| 28 | + return result; |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +} |
| 34 | + |
| 35 | +public class Solution { |
| 36 | + public static void main(String[] args) throws IOException { |
| 37 | + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); |
| 38 | + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); |
| 39 | + |
| 40 | + int stringsCount = Integer.parseInt(bufferedReader.readLine().trim()); |
| 41 | + |
| 42 | + List<String> strings = IntStream.range(0, stringsCount).mapToObj(i -> { |
| 43 | + try { |
| 44 | + return bufferedReader.readLine(); |
| 45 | + } catch (IOException ex) { |
| 46 | + throw new RuntimeException(ex); |
| 47 | + } |
| 48 | + }) |
| 49 | + .collect(toList()); |
| 50 | + |
| 51 | + int queriesCount = Integer.parseInt(bufferedReader.readLine().trim()); |
| 52 | + |
| 53 | + List<String> queries = IntStream.range(0, queriesCount).mapToObj(i -> { |
| 54 | + try { |
| 55 | + return bufferedReader.readLine(); |
| 56 | + } catch (IOException ex) { |
| 57 | + throw new RuntimeException(ex); |
| 58 | + } |
| 59 | + }) |
| 60 | + .collect(toList()); |
| 61 | + |
| 62 | + List<Integer> res = Result.matchingStrings(strings, queries); |
| 63 | + |
| 64 | + bufferedWriter.write( |
| 65 | + res.stream() |
| 66 | + .map(Object::toString) |
| 67 | + .collect(joining("\n")) |
| 68 | + + "\n" |
| 69 | + ); |
| 70 | + |
| 71 | + bufferedReader.close(); |
| 72 | + bufferedWriter.close(); |
| 73 | + } |
| 74 | +} |
0 commit comments