-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA-11849.cpp
More file actions
54 lines (46 loc) · 884 Bytes
/
UVA-11849.cpp
File metadata and controls
54 lines (46 loc) · 884 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
while(cin >> n >> m && n != 0 && m != 0){
long long temp;
long long count = 0;
if(n < m){
stack<long long> jack;
set<long long> jill;
for(long long i = 0; i < n; i++){
cin >> temp;
jack.push(temp);
}
for(long long i = 0; i < m; i++){
cin >> temp;
jill.insert(temp);
}
while(!jack.empty()){
if(jill.find(jack.top()) != jill.end()){
count++;
}
jack.pop();
}
}else{
set<long long> jack;
stack<long long> jill;
for(long long i = 0; i < n; i++){
cin >> temp;
jack.insert(temp);
}
for(long long i = 0; i < m; i++){
cin >> temp;
jill.push(temp);
}
while(!jill.empty()){
if(jack.find(jill.top()) != jack.end()){
count++;
}
jill.pop();
}
}
cout << count << endl;
}
return 0;
}