题目大意:
给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。
思路:
set
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
set<int>s;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
s.clear();
int flas=1;
while(n--)
{
int x;
scanf("%d",&x);
if(s.count(x))continue;
s.insert(x);
if(flas)flas=0;
else printf(" ");
printf("%d",x);
}
puts("");
}
return 0;
}