Advertisement
allia

сортировка подсчетом

Sep 16th, 2020
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. void rrr( int n)
  6. {
  7.   int l=0, arr[n], count[1000000];
  8.  
  9.   for (int i=0; i<n; i++)
  10.   cin >> arr[i];
  11.  
  12.   for (int i=0; i<1000000; i++)
  13.   count[i]=-1;
  14.  
  15.   for (int i=0; i<n ; i++)
  16.   count[arr[i]]++;
  17.  
  18.  for (int i=0; i<1000000 ; ++i)
  19.    for (int j=0; j<=count[i]; ++j)
  20.    {
  21.     arr[l]=i;
  22.     l++;
  23.    }
  24.  
  25.    for (int i=0; i<n; i++)
  26.   cout << arr[i] << " ";
  27.  
  28. }
  29. int main()
  30. {
  31.   int a=0;
  32.   cin >> a;
  33.   rrr (a);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement