Cod sursă (job #718168)

Utilizator avatar AlexD Alexandru Dima AlexD IP ascuns
Problemă Specsort (lot liceu) Compilator cpp-32 | 0,75 kb
Rundă Arhiva de probleme Status evaluat
Dată 5 mai 2023 22:15:37 Scor 100
#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;
}