-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommonElements.cpp
More file actions
77 lines (70 loc) · 1.45 KB
/
commonElements.cpp
File metadata and controls
77 lines (70 loc) · 1.45 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int tc;
cin >> tc;
while (tc--)
{
bool flag = 0;
ll x, y, z;
cin >> x >> y >> z;
set<ll> a;
set<ll> b;
set<ll> c;
for (auto i = 0; i < x; i++)
{
ll q;
cin >> q;
a.insert(q);
}
for (auto i = 0; i < y; i++)
{
ll q;
cin >> q;
b.insert(q);
}
for (auto i = 0; i < z; i++)
{
ll q;
cin >> q;
c.insert(q);
}
set<ll>::iterator it1;
set<ll>::iterator it2;
set<ll>::iterator it3;
it1 = a.begin();
it2 = b.begin();
it3 = c.begin();
while (it1 != a.end() && it2 != b.end() && it3 != c.end())
{
// cout<<*it1<<" "<<*it2<<" "<<*it3<<"\n";
if (*it1 == *it2 && *it2 == *it3)
{
flag = 1;
cout << *it1 << " ";
it1++;
it2++;
it3++;
}
else if (*it1 < *it2)
{
it1++;
}
else if (*it2 < *it3)
{
it2++;
}
else
{
it3++;
}
}
if (flag == 0)
{
cout << -1;
}
cout << "\n";
}
}