题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int>s; //使用集合将输入的数去重,并排序
int N; //随机数的个数
int n; //随机数
cin >> N;
while (N--) {
cin >> n;
s.insert(n); //使用集合去重并排序
}
//遍历输出随机数
for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
cout << *it << endl;
}
return 0;
}

查看11道真题和解析