BZOJ2761 repeated numbers and bzoj2761 repeated numbers

Source: Internet
Author: User

BZOJ2761 repeated numbers and bzoj2761 repeated numbers
Description

Given the number of N, it is required to remove the duplicates, only keep the number of first appearance.
For example, if the given number is 1 2 18 3 3 19 2 3 6 5 4, 2 and 3 have duplicates, the removed result is 1 2 18 3 19 6 5 4.

Input

Enter the first positive integer T, indicating that there are T groups of data.
Next, each group of data contains two rows. The first row is positive integer N, indicating N numbers. The second behavior is to remove N positive integers.

Output

For each group of data, one row is output, which is the remaining number after deduplication, and the numbers are separated by a space.

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

For 30% of data, 1 <=n <= 100, the given number is not greater than 100, all are non-negative integers;

For 50% of data, 1 <=n <= 10000, the given number is not greater than 10000, all are non-negative integers;

For 100% of data, 1 <= N <= 50000, the given number is within the range of 32-bit signed integers.

Code hash

Worker does not write hash data so far. It can only be used by 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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.