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;}