Advertisement
unknown_0711

Untitled

Oct 6th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner sc= new Scanner (System.in);
  10. HashMap<Integer, Integer> f= new HashMap<>();
  11. int n=sc.nextInt();
  12. int []a=new int[n];
  13. for(int i=0;i<n;i++)
  14. {
  15. a[i]=sc.nextInt();
  16. f.put(a[i], f.getOrDefault(a[i], 0)+1);
  17. }
  18. int m=sc.nextInt();
  19. int []b=new int[m];
  20. for(int i=0;i<m;i++){
  21. b[i]=sc.nextInt();
  22. f.put(b[i], f.getOrDefault(b[i], 0)-1);
  23. }
  24. int cnt=0;
  25. for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
  26. if(f.get(aa.getKey())!=0)cnt++;
  27. }
  28. int []ans= new int[cnt];
  29. int u=cnt;
  30. cnt=0;
  31. for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
  32. if(f.get(aa.getKey())!=0){ans[cnt]=aa.getKey(); cnt++;}
  33. }
  34. Arrays.sort(ans);
  35. for(int i=0;i<u;i++)System.out.print(ans[i]+" ");
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement