Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- Scanner sc= new Scanner (System.in);
- HashMap<Integer, Integer> f= new HashMap<>();
- int n=sc.nextInt();
- int []a=new int[n];
- for(int i=0;i<n;i++)
- {
- a[i]=sc.nextInt();
- f.put(a[i], f.getOrDefault(a[i], 0)+1);
- }
- int m=sc.nextInt();
- int []b=new int[m];
- for(int i=0;i<m;i++){
- b[i]=sc.nextInt();
- f.put(b[i], f.getOrDefault(b[i], 0)-1);
- }
- int cnt=0;
- for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
- if(f.get(aa.getKey())!=0)cnt++;
- }
- int []ans= new int[cnt];
- int u=cnt;
- cnt=0;
- for(HashMap.Entry<Integer, Integer> aa: f.entrySet()){
- if(f.get(aa.getKey())!=0){ans[cnt]=aa.getKey(); cnt++;}
- }
- Arrays.sort(ans);
- for(int i=0;i<u;i++)System.out.print(ans[i]+" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement