Advertisement
unknown_0711

Untitled

Oct 6th, 2022
25
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. a[i]=sc.nextInt();
  15. f.put(a[i], f.getOrDefault(a[i], 0)+1);
  16. }
  17. int m=sc.nextInt();
  18. int []b=new int[m];
  19. for(int i=0;i<m;i++){
  20. b[i]=sc.nextInt();
  21. f.put(b[i], f.getOrDefault(b[i], 0)-1);
  22. }
  23. int cnt=0;
  24. for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
  25. if(f.get(aa.getKey())!=0)cnt++;
  26. }
  27. int []ans= new int[cnt];
  28. int u=cnt;
  29. cnt=0;
  30. for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
  31. if(f.get(aa.getKey())!=0){ans[cnt]=aa.getKey(); cnt++;}
  32. }
  33. Arrays.sort(ans);
  34. for(int i=0;i<u;i++)System.out.print(ans[i]+" ");
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement