不重复数字

题目:         给出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;
}

[BZOJ2761] [JLOI2011] 不重复数字 (C++ STL - set)的更多相关文章

  1. [BZOJ2761][JLOI2011]不重复数字

    [BZOJ2761][JLOI2011]不重复数字 试题描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复 ...

  2. [BZOJ2761] [JLOI2011] 不重复数字 (set)

    Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...

  3. BZOJ2761:[JLOI2011]不重复数字(map)

    Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...

  4. BZOJ2761: [JLOI2011]不重复数字【set】【傻逼题】

    Description 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 ...

  5. bzoj2761: [JLOI2011]不重复数字(hash)

    题目大意:给出N个数,要求把其中重复的去掉,只保留第一次出现的数.例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. ...

  6. 【set】bzoj2761 [JLOI2011]不重复数字

    set去重. #include<cstdio> #include<set> using namespace std; set<int>S; ],b[],en; in ...

  7. [BZOJ2761][JLOI2011]不重复数字 暴力

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2761 直接暴力. #include<cstdio> #include<c ...

  8. bzoj 2761 [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3210  Solved: 1186[Submit][Sta ...

  9. BZOJ 2761: [JLOI2011]不重复数字 水题

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2100  Solved: 809 题目连接 http:// ...

随机推荐

  1. BJD4th pwn pi

    没记错的话,比赛那天正好是圣诞节,就只看了这一道pwn题,我还没做出来.我太菜了. 有一说一,ida换成7.5版本之后,一些去掉符号表的函数也能被识别出来了,ida更好用了呢. 题目程序分为两块,先看 ...

  2. 解决Tensorflow ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)

    问题描述 在将一个数组送入tensorflow训练时,报错如下: ValueError: Failed to convert a NumPy array to a Tensor (Unsupporte ...

  3. CF628B New Skateboard 题解

    Content 有一个长度为 \(n\) 的数字串 \(s\),求出有多少个子串能够被 \(4\) 整除. 数据范围:\(1\leqslant n\leqslant 3\times 10^5\). S ...

  4. IDEA快速创建一个简单的SpringBoot项目(需要联网)

    一.点击File-New-Project,选择Spring initializr ,选择jdk1.8及以上 二.填写相关信息,点击Next 3.选择Web -Spring Web,点击Next 4.输 ...

  5. JAVAWEB使用保存cookie、删除cookie、获取cookie工具类

    package com.test; import org.apache.commons.lang.StringUtils; import org.springframework.util.Assert ...

  6. win10使用cmake编译libevent(解决依赖openssl)

    概述 win10没有安装openssl cmake version: 3.18 libevent version: 2.1.10-stable libevent目前的版本中写好了 CMakeLists ...

  7. 【LeetCode】1470. 重新排列数组 Shuffle the Array (Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode-cn ...

  8. 【LeetCode】1046. Last Stone Weight 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 大根堆 日期 题目地址:https://leetco ...

  9. 【LeetCode】837. New 21 Game 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 相似题目 参考资料 日期 题目地址:htt ...

  10. 【LeetCode】278. First Bad Version 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二分查找 日期 题目地址:https://leetcode.c ...