BZOJ2761 不重複數字,bzoj2761重複數字

來源:互聯網
上載者:User

BZOJ2761 不重複數字,bzoj2761重複數字
題目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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.