Georgiy031

Untitled

Apr 14th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. void mysort(vector<int>& v) {
  9.     int amin = *min_element(v.begin(), v.end());
  10.     int amax = *max_element(v.begin(), v.end());
  11.     vector<int> b(amax - amin + 1, amax + 1);
  12.     for (int i = 0; i < v.size(); ++i) b[v[i] - amin] = i;
  13.     vector<int> res(v.size());
  14.     int ind = 0;
  15.     for (auto& x : res) {
  16.         while (b[ind] == amax + 1) ++ind;
  17.         x = v[b[ind++]];
  18.     }
  19.     v = res;
  20. }
  21.  
  22. int main() {
  23.     setlocale(LC_ALL, "Russian");
  24.     int n;
  25.     cout << "Введите длину массива: ";
  26.     cin >> n;
  27.     cout << "Введите массив: ";
  28.     vector<int> v(n);
  29.     for (auto& x : v) cin >> x;
  30.     mysort(v);
  31.     for (auto& x : v) cout << x << " ";
  32.     cout << endl;
  33. }
Add Comment
Please, Sign In to add comment