题目链接:
https://www.lydsy.com/JudgeOnline/problem.php?id=2761
题目大意:
给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
思路:
set
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
#define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Mem(a) memset(a, 0, sizeof(a))
#define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
#define MID(l, r) ((l) + ((r) - (l)) / 2)
#define lson ((o)<<1)
#define rson ((o)<<1|1)
#define Accepted 0
#pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
typedef long long ll;
const int MOD = ;//const引用更快,宏定义也更快
const double eps = 1e-;
const double pi = acos(-);
const int INF = 0x3f3f3f3f;
const int maxn = + ; set<int>s;
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, x, first = ;
scanf("%d", &n);
s.clear();
while(n--)
{
scanf("%d", &x);
if(s.count(x))continue;
s.insert(x);
if(first)first = ;
else printf(" ");
printf("%d", x);
}
puts("");
}
}