ZCMU-校赛D-1779
2016-12-27 15:02
239 查看
1779: 无法言表
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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
211
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 4Case #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;
}
相关文章推荐
- 判断NSString是否包含某个字符串
- JavaScipt 源码解析 css选择器
- PCA学习笔记
- 展望
- PHP中如何定义和使用常量
- spring boot 配置Filter过滤器
- Android Studio优秀插件汇总
- OpenStack网络指南(9)地址范围(Address scopes)
- ES elasticsearch
- Java常用类——String
- 展望
- java中volatile关键字的含义
- VS 安装助手,弹出“The security key for this program currently stored on your system does not appear to be ”
- 硬盘参数 PIO/DMA/UDMA/SWDMA/MWDMA
- js使用Switch达到切换不同颜色的效果
- ubuntu 加载新硬盘或分区
- C语言 · 2的次幂表示 · 幂方分解
- C# 重写WndProc 拦截 发送 系统消息 + windows消息常量值(2)
- 文章标题
- Android_ui之View与ViewGroup