Pagini recente » Cod sursa (job #2651807) | Atasamentele paginii Profil mihneat22 | Cod sursa (job #1312752) | Atasamentele paginii Profil EmanuelPutura | Cod sursa (job #1223366)
#include <cstdio>
#include <vector>
#include <algorithm>
#define MASK 255
#define DIM 1666013
using namespace std;
int N;
vector<int> V;
char buffer[DIM];
int poz = DIM - 1;
void scanf(int &A){
A = 0;
while('0' > buffer[poz] || buffer[poz] >'9')
if(++poz == DIM)
fread(buffer,1,DIM,stdin),poz = 0;
while('0' <= buffer[poz] && buffer[poz] <= '9'){
A = A * 10 + buffer[poz] - 48;
if(++poz == DIM)
fread(buffer,1,DIM,stdin),poz = 0;
}
}
void Sort(vector<int>&V,int disp)
{
vector<int> bucket[256];
for(int i = 0; i < (int)V.size(); ++i)
bucket[(V[i]>>disp) & MASK ].push_back(V[i]);
for(int i = 0,pz = 0; i <= 255; ++i)
for(int j = 0; j < (int) bucket[i].size(); ++j,++pz)
V[pz] = bucket[i][j];
}
void read()
{
scanf(N);
int b;
for(int i = 1; i <= N; ++i){
scanf(b);
V.push_back(b);
}
}
void Bucket()
{
for(int i = 0; i < 32; i += 8)
Sort(V,i);
}
int main()
{
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
read();
Bucket();
for(int i = 0; i < N; ++i )
printf("%d ",V[i]);
return 0;
}