题解 | #明明的随机数#C++

明明的随机数

http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

使用set集合就可以完成录入和输出

#include<iostream>
#include<set>
using namespace std;

int main() {
    int N;
    while(cin >> N) {
        set<int> set1;
        for (int i = 0; i < N; ++i) {
            int temp;
            cin >> temp;
            if (set1.count(temp) == 0) {
                set1.insert(temp);
            }
        }
        // C++11新特性:范围for循环、auto关键字
        for (auto index : set1) {
            cout << index << endl;
        }
    }
    return 0;
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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