【bzoj2761】【JLOI2011】不重复数字

来源:互联网 发布:python 股票行情 编辑:程序博客网 时间:2024/05/10 06:16

题目描述

给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。

输入

输入第一行为正整数T,表示有T组数据。
接下来每组数据包括两行,第一行为正整数N,表示有N个数。第二行为要去重的N个正整数。

输出

对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。

输入输出样例

Sample Input

2

11

1 2 18 3 3 19 2 3 6 5 4

6

1 2 3 4 5 6

Sample Output

1 2 18 3 19 6 5 4

1 2 3 4 5 6

题解

set乱搞即可,和中山市选那道沙比提有一拼
注意行尾不能有多余空格,否则会PE

My Code

/**************************************************************    Problem: 2761    User: infinityedge    Language: C++    Result: Accepted    Time:928 ms    Memory:1556 kb****************************************************************/#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include <vector>#include <set>using namespace std;int aa,t,n;int main(){    scanf("%d",&t);    while(t--){        set<int>mp;        bool b=false;        scanf("%d",&n);        for(int i=1;i<=n;i++){                       scanf("%d",&aa);            if(mp.count(aa))continue;            mp.insert(aa);            if(!b){                printf("%d",aa);                b=true;                continue;            }            printf(" %d",aa);           }        if(t>0)cout<<endl;    }}
0 0
原创粉丝点击