当前位置:网站首页>明明的随机数
明明的随机数
2022-07-04 17:59:00 【相思明月楼】
明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。
输入有2行 第1行为1个正整数,表示所生成的随机数的个数:N 第2行有N个用空格隔开的正整数,为所产生的随机数。
输出也是2行,第1行为1个正整数M,表示不相同的随机数的个数。第2行为M个用空格隔开的正整数,为从小到大排好序的不相同的随机数。
输入 10 |
输出 8 |
#include <cstdio>
#include <set>
#include <iostream>
using namespace std;
int main() {
set<int> s;
int n, x;
scanf("%d", &n);
while(n--) {
scanf("%d", &x);
s.insert(x);
}
printf("%d\n", s.size());
set<int>::iterator it = s.begin();
while(it != s.end()) {
printf("%d ", *it);
it++;
}
return 0;
}
边栏推荐
- 26. 删除有序数组中的重复项 C#解答
- 876. Intermediate node of linked list
- 2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
- Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
- Lm10 cosine wave homeopathic grid strategy
- ftp、sftp文件传输
- How to use async Awati asynchronous task processing instead of backgroundworker?
- Send and receive IBM WebSphere MQ messages
- Pointnet/Pointnet++点云数据集处理并训练
- The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
猜你喜欢

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

性能优化之关键渲染路径

小发猫物联网平台搭建与应用模型
redis分布式锁的8大坑总结梳理

Oracle with as ORA-00903: invalid table name 多表报错

Online sql to excel (xls/xlsx) tool

OpenCV的二值化处理函数threshold()详解

Go微服务(二)——Protobuf详细入门

整理混乱的头文件,我用include what you use
随机推荐
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
Perfect JS event delegation
在线文本行固定长度填充工具
FPGA时序约束分享01_四大步骤简述
数组中的第K个最大元素
Nebula Importer 数据导入实践
Shell 編程核心技術《四》
国元期货是正规平台吗?在国元期货开户安全吗?
Leetcode fizzbuzz C # answer
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Caché WebSocket
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
启牛开的证券账户安全吗?
利用策略模式优化if代码【策略模式】
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
Generate XML elements
Have you guys ever used CDC direct Mysql to Clickhouse
神经网络物联网应用技术就业前景【欢迎补充】
从实时应用角度谈通信总线仲裁机制和网络流控