Advertisement
anhkiet2507

TachVaTimTu

Oct 19th, 2022
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package ktgk;
  7.  
  8. import java.util.*;
  9.  
  10. /**
  11.  *
  12.  * @author nguyenanhkiet
  13.  * Tach va tim tu
  14.  */
  15. public class KTGK {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         Scanner cin = new Scanner(System.in);
  22.         int t = Integer.parseInt(cin.nextLine());
  23.         while(t-->0){
  24.             String s1 = cin.nextLine();
  25.             String s2 = cin.nextLine();
  26.             ArrayList<String> check = new ArrayList<>();
  27.             String s1t[] = s1.trim().split("\\s+");
  28.             for(String i : s1t){
  29.                 check.add(i.toLowerCase());
  30.             }
  31.             String s2t[] = s2.trim().split("\\s+");
  32.             for(String i : s2t){
  33.                 String temp = i.toLowerCase();
  34.                 int before = Collections.frequency(check, temp);
  35.                 check.add(temp);
  36.                 int after = Collections.frequency(check, temp);
  37.                 if(after - before == 1 && before != 0){
  38.                     System.out.print(i + " ");
  39.                 }
  40.             }
  41.             System.out.println();
  42.         }
  43.     }
  44.    
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement