fork download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. void count_sort(int a[], int n) {
  9. int count[100],b[n],j=0;
  10. for (int i=0; i<n; i++)
  11. count[i] = 0;
  12. for (int i=0; i<n; i++)
  13. ++count[a[i]];
  14. for (int i=1; i<n; i++)
  15. count[i] = count[i] + count[i-1];
  16. for (int i=0; i<n; i++)
  17. {
  18. b[count[a[i]]-1] = a[i];
  19. --count[a[i]];
  20. }
  21.  
  22. for (int i=0; i<100; i++)
  23. {
  24. for (;j<n;j++)
  25. if (b[j]>i)
  26. {
  27. cout<<j<<" ";
  28. break;
  29. }
  30. if (j>=n)
  31. cout<<j<<" ";
  32. }
  33.  
  34.  
  35. }
  36.  
  37. int main() {
  38. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  39. int n;
  40. cin>>n;
  41. int a[n];
  42.  
  43. for (int i=0; i<n; i++)
  44. cin>>a[i];
  45.  
  46. count_sort(a,n);
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 15240KB
stdin
10
4
3
0
1
5
1
2
4
2
4
stdout
1 3 5 6 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10