Pagini recente »
Cod sursă (job #718168)
Cod sursă (job
#718168)
#include<fstream>
#include<cmath>
using namespace std;
ifstream fin("specsort.in");
ofstream fout("specsort.out");
int n;
int p[50005];
int inc[50005],cnti;
int sf[50005],cnts;
signed main()
{
fin>>n;
for(int i=1;i<=n;i++)
fin>>p[i];
for(int i=0;(1<<i)<=n;i++)
{
cnti=cnts=0;
for(int j=1;j<=n;j++)
{
if((1<<i)&p[j])
sf[++cnts]=p[j];
else
inc[++cnti]=p[j];
}
for(int j=1;j<=cnti;j++)
{
fout<<inc[j]<<" ";
p[j]=inc[j];
}
for(int j=1;j<=cnts;j++)
{
fout<<sf[j]<<" ";
p[cnti+j]=sf[j];
}
fout<<"\n";
}
return 0;
}