Pagini recente » Cod sursa (job #2567598) | Cod sursa (job #2149640) | Cod sursa (job #1648639) | Monitorul de evaluare | Cod sursa (job #2488940)
#include <queue>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
long n, a, b, c, i, j, maxim, exp, v[10000100];
vector <long> cifra[15];
void sortare(long putere){
for(i=0; i<=9; i++){
cifra[i].clear();
}
for(i=1; i<=n; i++){
long x=(v[i]/putere)%10;
cifra[x].push_back(v[i]);
}
long k=0;
for(i=0; i<=9; i++){
for(j=0; j<cifra[i].size(); j++){
k++;
v[k]=cifra[i][j];
}
}
}
int main(){
fin>>n>>a>>b>>c;
v[1]=b%c;
maxim=b;
for(i=2; i<=n; i++){
v[i]=(a*v[i-1]%c+b)%c;
maxim=max(maxim, v[i]);
}
for(exp=1; exp<=maxim; exp*=10){
sortare(exp);
}
for(i=1; i<=n; i+=10){
fout<<v[i]<<" ";
}
}