Pagini recente » Monitorul de evaluare | Cod sursa (job #478637)
Cod sursa(job #478637)
#include<cstdio>
using namespace std;
int a[500000],b1[500000],b0[500000],n,i,c=1;
void sort (int A[],int n);
int main ()
{
freopen ("algsort.in","r",stdin);
freopen ("algsort.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;scanf("%d",&a[i]),++i);
for (i=1;i<=32;++i)
sort(a,n);
for (i=1;i<=n;printf("%d ",a[i]),++i);
return 0;
}
void sort (int A[],int n)
{
int i;
for (i=1;i<=n;++i)
if (A[i]&c)
b1[++b1[0]]=A[i];
else
b0[++b0[0]]=A[i];
for (i=1;i<=b0[0];++i)
A[i]=b0[i];
for (;i<=n;++i)
A[i]=b1[i-b0[0]];
b0[0]=b1[0]=0;
c=c<<1;
}