Advertisement
Guest User

cd zack

a guest
Nov 14th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. import java.io.InputStreamReader;
  2. import java.io.BufferedReader;
  3. import java.util.HashSet;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws Exception {
  7.         BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
  8.  
  9.         String line = scan.readLine();
  10.         String[] parts = line.split(" ");
  11.         int jack = Integer.parseInt(parts[0]);
  12.         int jill = Integer.parseInt(parts[1]);
  13.  
  14.         HashSet<String> hSet = new HashSet<>();
  15.        
  16.         while (true) {
  17.             int canSell = 0;
  18.             ;
  19.             for (int i=0; i<jack; i++) {
  20.                 String cd = scan.readLine();
  21.                 hSet.add(cd);
  22.            
  23.             }
  24.  
  25.             for (int i=0; i<jill; i++) {
  26.                 String cd = scan.readLine();
  27.                 if (hSet.contains(cd)){
  28.                     canSell++;
  29.                 }
  30.             }
  31.  
  32.             System.out.println(canSell);
  33.  
  34.             hSet.clear();
  35.    
  36.             line = scan.readLine();
  37.             parts = line.split(" ");
  38.             jack = Integer.parseInt(parts[0]);
  39.             jill = Integer.parseInt(parts[1]);
  40.  
  41.             if (jack == 0 && jill == 0) {
  42.                 break;
  43.             }
  44.         }
  45.    
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement