Advertisement
unknown_0711

Untitled

Oct 6th, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 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. int initial=f.getOrDefault(a[i], 0);
  16. f.put(a[i], initial+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. int initial=f.getOrDefault(b[i], 0);
  23. f.put(b[i], initial-1);
  24. }
  25. int cnt=0;
  26. for(HashMap.Entry<Integer, Integer> aa: f.entrySet())
  27. {
  28. if(f.get(aa.getKey())!=0)cnt++;
  29. }
  30. int []ans= new int[cnt];
  31. int u=cnt;
  32. cnt=0;
  33. for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
  34. if(f.get(aa.getKey())!=0){ans[cnt]=aa.getKey(); cnt++;}
  35. }
  36. Arrays.sort(ans);
  37. for(int i=0;i<u;i++)System.out.print(ans[i]+" ");
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement