Pagini recente » Cod sursa (job #2886395) | Cod sursa (job #2717108) | Cod sursa (job #1200281) | Cod sursa (job #858283) | Cod sursa (job #2611791)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("radixsort.in");
ofstream out("radixsort.out");
int n, nr[(1<<8) + 10], poz[(1<<8) + 10], v[N], aux[N];
int main()
{
long long a, b, c;
in >> n >> a >> b >> c;
v[0] = b;
int maxx = b;
for(int i = 1; i < n; i++)
{
v[i]=(a*v[i-1] + b) % c;
maxx = max(maxx, v[i]);
}
int B = (1 << 8), NC = 0;
while (maxx != 0)
{
NC++
maxx /= B;
}
int m = B - 1;
for(int k = 0; k < NC; k++){
for(int j = 0; j < B; j++){
nr[j] = 0;
}
for(int i = 0; i < n; i++){
int cif = v[i]/p % B;
nr[cif]++;
}
poz[0] = 0;
for(int j = 0; j < B; j++){
poz[j] = poz[j-1] + nr[j-1];
}
for(int i = 0; i < n; i++){
int cif = v[i]/p % B;
aux[poz[cif]++] = v[i];
}
for(int i = 0; i < n; i++){
v[i] = aux[i];
}
p *= B;
}
for(int i = 0; i < n; i += 10)
{
out << v[i] << " ";
}
return 0;
}