Cod sursa(job #1294533)

Utilizator valen.valentinValentin Valeanu valen.valentin Data 17 decembrie 2014 19:31:02
Problema Radix Sort Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.82 kb
program radixsort;
type
tabel=array[0..1000005] of longint;
tab=array[0..256] of longint;
buf=array[0..1 shl 17] of char;
var
ff1,ff2:buf;
v,aux:tabel; x:tab;
y:int64;
i,j,a,b,c,n:longint;
f1,f2:text;
begin
assign (f1,'radixsort.in');
assign (f2,'radixsort.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n,a,b,c);
for i:=1 to n do begin
y:=(a*v[i-1]+b) mod c;
v[i]:=y;
end;
i:=0;
repeat
for j:=1 to 255 do x[j]:=0;
for j:=1 to n do
x[(v[j] shl i) and 255]:=x[(v[j] shl i) and 255]+1;
for j:=1 to 255 do
x[j]:=x[j]+x[j-1];
for j:=n downto 1 do begin
aux[x[(v[j] shl i) and 255]]:=v[j];
dec(x[(v[j] shl i) and 255]); end;
for j:=1 to n do
v[j]:=aux[j];
i:=i+8;
until i>24;
i:=1;
repeat
write(f2,v[i],' ');
i:=i+10;
until i>n;
close (f1);
close (f2);
end.