题解 | #明明的随机数#
明明的随机数
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")


