Pagini recente » Cod sursa (job #1550385) | Cod sursa (job #2038588) | Cod sursa (job #96835) | Cod sursa (job #755881) | Cod sursa (job #1094307)
#include <fstream>
#include <queue>
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
queue <int> R[2][256];
int x, bits = 255,n,a,b,c,t;
int main()
{
fin>>n>>a>>b>>c;
x = b;
R[0][bits&x].push (x);
for (int i=2; i<=n; ++i)
{
x = (a*x + b)%c;
R[0][bits&x].push (x);
}
for (int i=1,ok=0; i<=3; ok = 1-ok,++i)
{
for (int j=0; j<256; ++j)
{
while (!R[ok][j].empty())
{
int x= R[ok][j].front();
R[1-ok][(x>>(i*8))&bits].push (x);
R[ok][j].pop();
}
}
}
for (int j=0; j<256; ++j)
{
while (!R[1][j].empty())
{
++t;
if (t%10==1)
fout<<R[1][j].front()<<" ";
R[1][j].pop();
}
}
}