Cod sursa(job #1248221)

Utilizator radudorosRadu Doros radudoros Data 24 octombrie 2014 19:50:25
Problema Radix Sort Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <queue>
#include <fstream>
#include <limits>
using namespace std;

queue <unsigned int> a[256];
unsigned int v[10000000];

ifstream fin("radixsort.in");
ofstream fout("radixsort.out");





int main()
{
	int n,A,B,C;
	fin >> n>> A>> B>> C;
	v[1] = B;
	for (int i = 2; i <= n; i++)
	{
		v[i]=(unsigned int)((unsigned long long)(A*v[i-1]+B)%C);
	}
	bool sortat = 0;
	unsigned long long k = 1<<8;
	unsigned long long aux = 1;

	while (k<=(aux <<32))
	{
		for (int i = 1; i <= n; i++)
		{
			if (k == 256)
				a[v[i] % (k) / (k >> 8)].push(v[i]);
			else
				a[v[i] / (k >> 8)*(k >> 8) % k / (k >> 8)].push(v[i]); /*De imbunatatit chestia asta!!*/
		}
		int h = 0;
		for (int i = 0; i <= 255; i++)
		{
			
			while (!a[i].empty())
			{
				h++;
				v[h]= a[i].front();
				a[i].pop();
			}
		}
		k <<=8;
	}
	for (int i = 1; i <= n; i+=10)
	{
		fout << v[i] << ' ';
	}



}