题解 | 明明的随机数

明明的随机数

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;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务