BZoj 2761: [JLOI2011]不重复数字 (set

来源:互联网 发布:做广告的软件 编辑:程序博客网 时间:2024/05/24 06:30

2761: [JLOI2011]不重复数字

Description

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

Input

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

Output

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

Sample Input

2111 2 18 3 3 19 2 3 6 5 461 2 3 4 5 6

Sample Output

1 2 18 3 19 6 5 41 2 3 4 5 6

Hint

题解:

我看聚聚标签上面写个离散化结果这么水QAQ
去重 set

AC代码

#include <bits/stdc++.h>using namespace std;set<int>st;int main(){    int T;    scanf("%d",&T);    while(T--) {        st.clear();        int n,x;        scanf("%d",&n);        scanf("%d",&x);        st.insert(x);        printf("%d",x);        for(int i = 0;i < n-1; i++) {            scanf("%d",&x);            if(st.count(x)==0)  {                printf(" %d",x);                st.insert(x);;            }        }        printf("\n");    }return 0;}
0 0
原创粉丝点击