题解 | 明明的随机数
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
#include <iostream>
#include <unordered_set>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
set<int> set1; // 使用 set关联容器实现,其拥有只接受唯一元素并自动排序的功能,其数据结构为红黑树
// 读取 n 个随机整数
for (int i = 0; i < n; i++) {
int num;
cin >> num;
set1.insert(num); // 插入set1 中
}
// 输出结果
for (int num : set1) {
cout << num << endl;
}
return 0;
}
查看12道真题和解析