Description
给出N个数,要求把其中的重复的去掉,只保留第一次出现的数.1 <= N <= 50000,给出的数在32位有符号整数范围内。
Input
第一行T(T<=10),接下来一个数n,接下来n个数
Output
Case #x: y1,y2,...,x是测试编号从1开始,y_i表示答案
Sample Input
2
11
1 2 18 3 3 19 2 3 6 5 4
6
1 2 3 4 5 6
Sample Output
Case #1: 1 2 18 3 19 6 5 4
Case #2: 1 2 3 4 5 6
代码
#include<stdio.h>
#include<map>
#include<iostream>
using namespace std;
map<long long,int> s;
int main()
{
int T,Case=1;
scanf("%d",&T);
while(T--)
{
int n,flag=0;
long long x;
scanf("%d",&n);
s.clear();
for(int i=0;i<n;i++)
{
scanf("%lld",&x);
s[x]+=1;
if(s[x]==1)
{
if(!flag)
{
printf("Case #%d: ",Case);
printf("%lld",x);
flag=1;
}
else
printf(" %lld",x);
}
}
Case+=1;
printf("\n");
}
return 0;
}