Cod sursa(job #109392)

Utilizator loriKis Levente Lorand lori Data 25 noiembrie 2007 10:43:22
Problema Ordine Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 1, Clasele 5-8 Marime 0.76 kb
const aux:array [1..26] of char=('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
var c:char;
    vn:array ['a'..'z'] of longint;
    vc:array [1..1000000] of char;
    i,k,max:longint;
begin
 assign(input,'ordine.in'); reset(input);
 assign(output,'ordine.out'); rewrite(output);
  while not eoln do begin
   read(c); inc(vn[c]);
  end;
  for c:='a' to 'z' do begin
   i:=1; k:=1; max:=1;
   while vn[c]<>0 do begin
    k:=1;
    while ((vc[i]<>chr(0)) or (k<=3)) or ((vc[i]<>chr(0)) and (max=1)) do begin
     inc(i); inc(k);
    end;
    vc[i]:=c; dec(vn[c]); inc(max);
   end;
  end;
  for i:=1 to 1000000 do
   if vc[i]<>chr(0) then write(vc[i]);
  writeln;
 close(input); close(output);
end.