d190: 11462 - Age Sort
Tags: counting-sort
出處:https://zerojudge.tw/ShowProblem?problemid=d190
提交:https://zerojudge.tw/Submissions?problemid=d190&account=allllllan123456
問題:給定 $n\in[1,2000000]$ 個人介於 $[1,99]$ 的年齡,請輸出這些人年齡的排序。
解法:就 counting sort,不解釋。
1#include <bits/stdc++.h>
2using namespace std;
3
4int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // IO 優化
5 int n, t, count[100];
6 while (cin >> n) {
7 memset(count, 0, sizeof count);
8 while (n--) cin >> t, count[t]++;
9 for (int i=1; i<100; i++)
10 while (count[i]--) cout << i << ' ';
11 cout << '\n';
12 }
13 return 0;
14}