Pagini recente » Cod sursa (job #1675363) | Cod sursa (job #116204) | Cod sursa (job #476343) | Cod sursa (job #1261805) | Cod sursa (job #2194237)
#include <bits/stdc++.h>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int N, x, y, z, MAX, M;
vector<int> a, nr[10];
int main()
{
f >> N >> x >> y >> z;
a.push_back(y);
for(int i = 1; i < N; i++)
a.push_back((x * a[i - 1] + y) % z), MAX = max(MAX, a[i]);
M = 1;
while(MAX) M *= 10, MAX /= 10;
for(int p = 1; p <= M; p *= 10) {
for(auto i = a.begin(); i != a.end(); i++)
nr[*i / p % 10].push_back(*i);
a.clear();
for(int i = 0; i <= 9; i++) {
for(auto j = nr[i].begin(); j != nr[i].end(); j++)
a.push_back(*j);
nr[i].clear();
}
}
for(auto i = a.begin(); i != a.end(); i += 10)
g << *i << " ";
g << "\n";
return 0;
}