您的位置:首页 > 其它

ZCMU-校赛D-1779

2016-12-27 15:02 239 查看

1779: 无法言表

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 149  Solved: 50

[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好东西啊。标记过的元素就代表已经输出过了,没有标记的代表还没输出。#include<iostream>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
map<long long,int>a;
int main()
{
int n,m,p,count1=0;
scanf("%d",&n);
while(n--)
{
count1++;
a.clear();
scanf("%d",&m);
printf("Case #%d:",count1);
for(int i=0;i<m;i++)
{
scanf("%d",&p);
if(a[p])
continue;
else
{
a[p]=1;
printf(" %d",p);
}
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: