题解 | 明明的随机数
#include <iostream> #include <set> using namespace std; int main() { int a; set<int> s; int count = 0; cin >> count; int num = 0; // 输入 while (cin >> a) { if (a < 1 || a > 500) { break; } s.insert(a); ++num; if (num >= count) { break; } } // 输出 set<int>::const_iterator it = s.begin(); for (; it != s.end(); ++it) { cout << *it << endl; } }