Pagini recente » Cod sursa (job #2716657) | Cod sursa (job #530310) | Cod sursa (job #2175650) | Cod sursa (job #3254063) | Cod sursa (job #1731803)
#include <iostream>
#include <fstream>
using namespace std;
const int nmax = 10000001;
int a[nmax];
int temp[nmax];
int *ap = a, *tempp = temp, *aux;
int counts[100];
int n;
int A,B,C;
void counting(int digit);
void radixSort();
int main()
{
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
ap = a;
tempp = tempp;
fin >> n;
fin >> A >> B >> C;
a[0] = B%C;
for(int i=1; i<n; i++)
{
a[i] = (1LL * A * a[i-1] % C + B) % C;
}
radixSort();
for(int i=0; i<n; i+=10)
{
fout << ap[i] << " ";
}
fin.close();
fout.close();
return 0;
}
void radixSort()
{
int maxNumber = ap[0];
int i;
for(i=1 ; i<n; i++)
if(ap[i] > maxNumber)
maxNumber = ap[i];
for(int digit = 1; maxNumber/digit > 0; digit*= 100)
{
for(i=0; i<n; i++)
{
counts[(ap[i]/digit)%100]++;
}
for(i=1; i<100; i++)
{
counts[i] +=counts[i-1];
}
for(i=n-1; i>=0; i--)
{
tempp[counts[(ap[i]/digit)%100]-1] = ap[i];
counts[(ap[i]/digit)%100]--;
}
for(int i=0;i<100; i++)
counts[i] =0;
aux = ap;
ap = tempp;
tempp = aux;
}
}