Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.InputStreamReader;
- import java.io.BufferedReader;
- import java.util.HashSet;
- public class Main {
- public static void main(String[] args) throws Exception {
- BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
- String line = scan.readLine();
- String[] parts = line.split(" ");
- int jack = Integer.parseInt(parts[0]);
- int jill = Integer.parseInt(parts[1]);
- HashSet<String> hSet = new HashSet<>();
- while (true) {
- int canSell = 0;
- ;
- for (int i=0; i<jack; i++) {
- String cd = scan.readLine();
- hSet.add(cd);
- }
- for (int i=0; i<jill; i++) {
- String cd = scan.readLine();
- if (hSet.contains(cd)){
- canSell++;
- }
- }
- System.out.println(canSell);
- hSet.clear();
- line = scan.readLine();
- parts = line.split(" ");
- jack = Integer.parseInt(parts[0]);
- jill = Integer.parseInt(parts[1]);
- if (jack == 0 && jill == 0) {
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement