-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-sachin-virat.cpp
49 lines (40 loc) · 1.05 KB
/
1-sachin-virat.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
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
int t;
std::cin >> t;
for (int test = 0; test < t; test++) {
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
std::vector<int> result;
int i = 0, j = 0;
while (i < n && j < n) {
if (a[i] == b[j]) {
result.push_back(a[i]);
i++;
j++;
} else if (a[i] < b[j]) {
i++;
} else {
j++;
}
}
std::sort(result.begin(), result.end());
// Print the unique elements from the result
auto last = std::unique(result.begin(), result.end());
result.erase(last, result.end());
for (int i = 0; i < result.size(); i++) {
std::cout << result[i] << " ";
}
std::cout << std::endl;
}
return 0;
}