P1059. 明明的随机数

考点

  • 排序

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>

using namespace std;

const int LEN = 1001;

int arr[LEN], ans[LEN], idx;

int main()
{
int n, in;
cin >> n;
while (n--)
{
cin >> in;
++arr[in];
}
for (int i = 0; i < LEN; ++i)
if (arr[i])
ans[idx++] = i;
cout << idx << endl;
for (int i = 0; i < idx; ++i)
cout << ans[i] << " ";
return 0;
}

思路

数字最大也才到1000,直接使用计数排序就行