P4305. 不重复数字

考点

  • 模拟

题解

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
#include <bits/stdc++.h>
using namespace std;
const int LEN = 5e4 + 50;
int n;
unordered_map<int, bool> mp;

void f() {
int in;
cin >> n;
while (n--) {
cin >> in;
if (!mp.count(in)) {
cout << in << " ";
mp[in] = true;
}
}
mp.clear();
cout << endl;
}

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) f();
return 0;
}

思路

哈希表记录是否出现过即可