-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmissing_number.cpp
65 lines (61 loc) · 1.48 KB
/
missing_number.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std ;
int main()
{
int n , m;
//cout<<"n\n";
cin>>n ;
vector <int > arr(n) ;
map<int,int> x ;
for(int i =0 ; i<n ; i++)
{
cin>>arr[i] ;
x[arr[i]]++ ;
}
/*for( map<int ,int>::iterator it = x.begin() ; it!=x.end() ; ++it )
{
cout<<it->first<<" "<<it->second<<"\n" ;
} */
//cout<<"m\n" ;
cin >> m;
vector <int > brr(m) ;
map<int,int> y ;
for(int i =0 ; i<m ; i++)
{
cin>>brr[i] ;
y[brr[i]]++ ;
}
/*for( map<int ,int>::iterator it = y.begin() ; it!=y.end() ; ++it )
{
cout<<it->first<<" "<<it->second<<"\n" ;
} */
vector <int> result ;
for(map<int ,int>::iterator it = y.begin() ; it!=y.end() ; it++ )
{
if(count(arr.begin(),arr.end(),it->first)==0) //Element not in arr
result.push_back(it->first ) ;
else if(count(arr.begin(),arr.end(),it->first)!=count(brr.begin(),brr.end(),it->first))
result.push_back(it->first ) ;
}
sort(result.begin() , result.end() ) ;
for(auto q:result)
cout<<q<<" " ;
/*
for(int i = 0 , j=0 ;i<n && j<m ;i++ , j++)
{
if(arr[i] != brr[j])
{
if(count[brr[j]]==0)
{
cout<<brr[j]<<" ";
count[brr[j]]++ ;
j++;
}
}
}
*/
return 0;
}