不重复数字

题目:         给出N个数,要求把其中重复的去掉,只保留第一次出现的数。例如,给出的数

为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4。

Input:       输入第一行为正整数T,表示有T组数据。接下来每组数据包括两行,第一行为

正整数N,表示有N个数。第二行为要去重的N个正整数。

Output:    对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。

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:        对于30%的数据,1 <= N <= 100,给出的数不大于100,均为非负整数;

对于50%的数据,1 <= N <= 10000,给出的数不大于10000,均为非负整数;

对于100%的数据,1 <= N <= 50000,给出的数在32位有符号整数范围内。

  提示:          由于数据量很大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。


代码如下:

#include <iostream>
#include <cstdio>
#include <set> using namespace std;
set <int> num; int main(void)
{
int t, n, a; scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &a);
num.insert(a); printf("%d", a);
for (int i = 1; i < n; i++) {
scanf("%d", &a); if (num.find(a) == num.end()) { // 若数字不重复
num.insert(a);
printf(" %d", a);
}
}
printf("\n"); num.clear();
} return 0;
}

最新文章

  1. salesforce 零基础学习(五十九)apex:param使用以及相关的疑惑
  2. java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter
  3. jquery selector checkbox
  4. Linux 文件与目录
  5. iOS完结篇
  6. uva 10036 Problem C: Divisibility
  7. IWorkspaceFactory接口
  8. angularjs---服务(service / factory / provider)
  9. css:background-position &gt; 精灵技术
  10. 五、Html表单标签
  11. devDependencies和dependencies的版本写法
  12. 接触新的项目,构建时候报错:Failure to find io.netty:netty-tcnative:jar:${os.detected.classifier}:2.0.7.Final in
  13. flink-kafka-connector 的实现
  14. 2.QT-窗口组件(QWidget),QT坐标系统,初探消息处理(信号与槽)
  15. 测试技术/网游Bug分析/单机修改 视频教程
  16. 12、多线程:Threading、守护线程
  17. 逆袭之旅DAY15.东软实训.Oracle.约束、序列、视图、索引、用户管理、角色
  18. 【Redis】Redis学习(七) Redis 持久化之RDB和AOF
  19. Linux笔记 #07# 搭建机器学习环境
  20. Codeforces 830B - Cards Sorting 树状数组

热门文章

  1. pwnable_start (内联汇编)
  2. Sysenter/Kifastcallentry hook 检测与恢复
  3. 【WP】【web】中学生CTF | web部分wp
  4. 基于MCRA-OMLSA的语音降噪(一):原理
  5. CF19A World Football Cup 题解
  6. java 数据类型:集合接口Collection之 Stream 的reduce方法
  7. Java的垃圾回收机制:强制回收System.gc() Runtime.getTime().gc()
  8. 分享 NET 5.x 自定义文件日志实现 原汁原味
  9. 简单聊聊mysql的脏读、不可重复读
  10. velocity使用foreach进行遍历时$velocityCount不起作用