题解 | #明明的随机数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
使用哈希表来进行数据统计,统计完毕后,遍历哈希表,若其值大于0,则输出其下标就是存在的数据。
Code:
#include <iostream>
using namespace std;
int main() {
int num;
int n;
while (cin >> n) {
int hash[1001] = {0};
while(n--) {
cin >> num;
hash[num]++;
}
for (int i = 0; i < 1001; i++) {
if (hash[i] > 0) {
cout << i << endl;
}
}
}
return 0;
}