Cod sursa(job #2642688)

Utilizator lucametehauDart Monkey lucametehau Data 16 august 2020 19:24:50
Problema Sortare prin comparare Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb

#include <fstream>
#include <vector>

using namespace std;

ifstream cin ("algsort.in");
ofstream cout ("algsort.out");

int n;

int v[500005];
vector <int> nr[16];

int main() {
  cin >> n;
  for(int i = 1; i <= n; i++)
    cin >> v[i];
  for(int j = 0; j < 8; j++) {
    for(int i = 1; i <= n; i++)
      nr[(v[i] >> (j * 4)) & 15].push_back(v[i]);
    int m = 0;
    for(int i = 0; i < (1 << 4); i++) {
      for(auto &j : nr[i])
        v[++m] = j;
      nr[i].clear();
    }
  }
  for(int i = 1; i <= n; i++)
    cout << v[i] << " ";
  return 0;
}