Pagini recente » Cod sursa (job #1022201) | Cod sursa (job #2381301) | Cod sursa (job #2932596) | Cod sursa (job #1271322) | Cod sursa (job #1540801)
#include<fstream>
#include<iostream>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int n;
unsigned long long v[10000001];
int getMax(unsigned long long a[])
{
int maxi = a[0];
for (int i = 1; i < n; i++)
if (a[i] > maxi)
maxi = a[i];
return maxi;
}
void countSort( unsigned long long a[],int exp)
{
int output[n];
int i, countt[10] = {0};
for (i = 0; i < n; i++)
countt[ (a[i]/exp)%10 ]++;
for (i = 1; i < 10; i++)
countt[i] += countt[i - 1];
for (i = n - 1; i >= 0; i--)
{
output[countt[ (a[i]/exp)%10 ] - 1] = a[i];
countt[ (a[i]/exp)%10 ]--;
}
for (i = 0; i < n; i++)
a[i] = output[i];
}
void radixsort(unsigned long long a[], int n)
{
int m = getMax(v);
for (int exp = 1; m/exp > 0; exp *= 10)
countSort( v,exp);
}
int main()
{
int a, b, c,i;
f>>n>>a>>b>>c;
v[0]=b;
i=1;
while(i<n)
{
v[i] =(a * v[i-1] + b) % c;
i++;
}
radixsort(v,n);
for(i=0; i<n; i+=10) g<<v[i]<<" ";
return 0;
}