Pagini recente » Cod sursa (job #1648501) | Cod sursa (job #2699528) | Cod sursa (job #554951) | Cod sursa (job #636559) | Cod sursa (job #1780638)
#include <cstdio>
#include <queue>
#define Mlen 10000000
#define type unsigned long long
using namespace std;
queue <type> galetzi[10];
type cifra=1,v[Mlen];
int n;
int dacif(type a)
{
type x=(type)cifra/10;
a=(type)a%cifra;
a=(type)a/x;
return a;
}
void galeteala()
{
cifra=(type)cifra*10;
int cif;
for(int i=0;i<n;++i)
cif=dacif(v[i]),
galetzi[cif].push(v[i]);
bool ok=0;
for(int i=0,k=0;i<10;++i)
{
if(i&&!galetzi[i].empty())ok=1;
while(!galetzi[i].empty())
v[k++]=galetzi[i].front(),
galetzi[i].pop();
}
if(ok)galeteala();
}
void genesa(int n,type a, type b, type c)
{
v[0]=b;
for(int i=1;i<n;++i)
v[i]=(type)((type)a*v[i-1]+b)%c;
}
int main()
{
FILE *in=fopen("radixsort.in","r"),*out=fopen("radixsort.out","w");
type a,b,c;
fscanf(in,"%d%llu%llu%llu",&n,&a,&b,&c);
genesa(n,a,b,c);
galeteala();
for(int i=0;i<n;i+=10)
fprintf(out,"%lu ",v[i]);
return 0;
}