码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ2761 不重复数字

时间:2015-02-23 14:19:21      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:stl

题目

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

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

HINT

对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;

对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;

对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。

代码

hash

蒟蒻至今不会写hash,只能用stl水过

#include<cstdio>
#include<bits/stdc++.h>
#include<cstring>
#include<cstdlib>
#define R0(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
int main(){
    int t=read();
    while(t--){
        int n=read();
        set<int>S;
        vector<int>ans;
        R0(i,n){
            int tmp=read();
            if(S.count(tmp))continue;
            S.insert(tmp);
            ans.push_back(tmp);
        }
        R0(i,ans.size()-1)printf("%d ",ans[i]);
        printf("%d\n",ans[ans.size()-1]);
    }
    return 0;
}

BZOJ2761 不重复数字

标签:stl

原文地址:http://blog.csdn.net/iostream0/article/details/43916171

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!