考点
题解
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;
int N, M, arr[1000];
void counting_sort() { for (int i = 1; i <= 1000; ++i) while (arr[i]--) cout << i << " "; }
int main() { int num; cin >> N >> M; for (int i = 1; i <= M; ++i) { cin >> num; ++arr[num]; } counting_sort(); return 0; }
|
思路
本质上是根据每种数字出现的个数来输出,故而使用计数排序即可