题解 | #明明的随机数#

明明的随机数

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

使用set去除重复,之后排序输出

#include <algorithm>
#include <iostream>
#include <map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
    int nums;
    cin >> nums;

    std::unordered_set<int> hash;
    
    for(int i = 0; i < nums; i ++){
        int input = 0;
        cin >> input;
        // cout << input << endl;
        if(hash.find(input) == hash.end())
            hash.insert(input);
        
    }

    int len = size(hash);
    std::vector<int> res;
    for(auto it = hash.begin(); it != hash.end(); it++)
        res.push_back(*it);
        // cout<< *it << endl;
    
    sort(res.begin(), res.end());

    for(int i = 0; i < len; i ++)
        cout << res[i] << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

计算机类的会考啥啊
投递中国电信等公司10个岗位
点赞 评论 收藏
分享
09-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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