题解 | #明明的随机数#

明明的随机数

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 09:19
已编辑
沈阳农业大学 C++
修订
丿南烟丶:个人评价可以删掉 两个项目都是轮子项目,把一个转换成应用型项目,把MySQL和redis用起来 另外项目的时间可以标明一下
最后再改一次简历
点赞 评论 收藏
分享
小肥罗:此乃引蛇出洞之计,勾出你想去杭州的原因再告诉你不在杭州,让你打脸,自己离开。好一招抛砖引玉,虾仁猪心。你回复:计划去杭州,但我心中第一选择是宁波~巧了! 这计名叫“阿Q精神胜利法之厚脸皮不要脸我不尴尬谁爱尴尬谁尴尬去”之计!克制一切!
这个工作能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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