题解 | #明明的随机数#

明明的随机数

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

根据题目可知,输出数据需要排序且不能重复,这不就是set容器的特性吗!话不多说,上代码

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

int main(){
    std::set<int> nums;
    int n = 0;
    int val;
    while(cin>>n){
        while(n--){
            cin >> val;
            nums.emplace(val);
        }
        for(auto it = nums.begin();it!= nums.end();++it){
            cout<<*it<<endl;
        }
        nums.clear();
    }

    return 0;
}
全部评论

相关推荐

头像
05-13 11:19
C++
点赞 评论 收藏
转发
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务