这是快读模板:
int read() {
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())if (c == '-')f = -1;
for (; isdigit(c); c = getchar())x = x * 10 + c - 48;
return x * f;
}
哈希表创建:unordered_map<int, long long>a;
这次以洛谷《P4305 [JLOI2011]不重复数字》为例。
#include<bits/stdc++.h>
using namespace std;
long long t, n, tmp;
unordered_map<int, long long>a;//哈希表
int read() {//快读模板
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())if (c == '-')f = -1;
for (; isdigit(c); c = getchar())x = x * 10 + c - 48;
return x * f;
}
int main() {
t=read();
for(int i=1;i<=t;i++){
a.clear();
n=read();
for(int i=1;i<=n;i++){
tmp=read();
a[tmp]++;
if(a[tmp]==1)cout<<tmp<<' ';
}
cout<<endl;
}
return 0;
}