题解 | #明明的随机数#C++
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
使用set集合就可以完成录入和输出
#include<iostream>
#include<set>
using namespace std;
int main() {
int N;
while(cin >> N) {
set<int> set1;
for (int i = 0; i < N; ++i) {
int temp;
cin >> temp;
if (set1.count(temp) == 0) {
set1.insert(temp);
}
}
// C++11新特性:范围for循环、auto关键字
for (auto index : set1) {
cout << index << endl;
}
}
return 0;
}
查看9道真题和解析