题解 | #明明的随机数#

明明的随机数

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

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

int main() {
    int n, a = 0;
    cin >> n;
    set<int> s;
    while (cin >> a) {
        s.insert(a);	//用set容器存储所有输入元素,去重又排序
    }

    vector<int> vec;
    vector<int>::iterator it;
    vec.assign(s.begin(), s.end());		//用vector接收并打印
    for (it = vec.begin(); it != vec.end(); it++){
        cout << *it << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

永不遗忘:才这么点算什么拉黑,我初筛连着挂几十次了,最后还是能进面
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务