Cod sursa(job #2192695)

Utilizator PredaBossPreda Andrei PredaBoss Data 6 aprilie 2018 21:28:54
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("radixsort.in");
ofstream fout("radixsort.out");
int n,a,b,c;
vector<long long>elem;
vector<int>bucket[260];
int main()
{
    fin>>n>>a>>b>>c;
    elem.push_back(b);
    for(int i=1;i<n;i++)
        elem.push_back((a*elem[i-1]+b)%c);
    long long t=1;
    long long q=256;
    for(int p=1;p<=4;p++)
    {
        for(int i=0;i<n;i++)
        {
            if(elem[i]/t==0)
            {
                bucket[0].push_back(elem[i]);
                continue;
            }
            bucket[(elem[i]/t)%q].push_back(elem[i]);
        }
        int cou=0;
    for(int j=0;j<=255;j++)
    {
        for(int g=0;g<bucket[j].size();g++)
        {
            elem[cou]=bucket[j][g];
            cou++;
        }
        bucket[j].clear();
    }
    t*=256;
    }
    int pos=0;
    while(pos<n)
    {
        fout<<elem[pos]<<" ";
        pos+=10;
    }
    return 0;
}