1779: 无法言表
Time Limit: 1 Sec
Memory Limit: 128 MB
[Submit][Status][Web Board]
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
【分析】
判重...我不是很清楚正确做法是什么,但是我是用map直接标记的....这里不得不夸一下map真是个好东西~
map<long long ,int>直接标记~
这里要提一点,我一开始作死用map<string,int>标记...cin>>超时了...尴尬的不要不要的 所以~ 记得读取的多了了就尽量别用cin>>咯
【代码】
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include <map>
using namespace std;
#define INF 0x7ffffff
map <long long,int> a;
int main()
{
long long x;
int pp;scanf("%d",&pp);
for (int p=1;p<=pp;p++)
{
a.clear();
int n;
scanf("%d",&n);
printf("Case #%d:",p);
for (int i=0;i<n;i++)
{
scanf("%lld",&x);
if (a[x]) continue;
a[x]=1;
printf(" %lld",x);
}
printf("\n");
}
return 0;
}