Pagini recente » Istoria paginii runda/jc2015-runda1 | Cod sursa (job #3290730) | Cod sursa (job #24960) | Cod sursa (job #1915707) | Cod sursa (job #1693331)
#include <bits/stdc++.h>
using namespace std;
const int nmax = 100000000;
vector <int> w[10];
int main() {
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int *v = new int[nmax];
int n, a, b, c;
f>>n>>a>>b>>c;
v[0] = b;
for(int i=1; i<n; i++)
v[i] = (a * v[i-1] + b) % c;
for(int k=10; k<=1000000000; k*=10) {
for(int i=0; i<n; i++)
w[(v[i]%k) / (k/10)].push_back(v[i]);
int i=0;
for(int digit=0; digit<10; digit++) {
for(auto x:w[digit])
v[i++] = x;
w[digit].clear();
}
}
for(int i=0; i<n; i+=10)
g<<v[i]<<" ";
g<<"\n";
return 0;
}