Cod sursa(job #227820)

Utilizator DanielGGlodeanu Ioan Daniel DanielG Data 5 decembrie 2008 16:46:25
Problema Ordine Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.98 kb
var v:array[1..26] of longint;
f:text; c:char; j,uu,a,i,unu,doi:longint;
ok:boolean;
procedure citire;
begin
assign(f,'ordine.in');reset(f);
while not eof(f) do
      begin
      read(f,c);
      inc(v[ord(c)-97+1]);
      end;
close(f);
end;
begin
citire;
unu:=1;
doi:=2;
i:=1;
ok:=false;
assign(f,'ordine.out');rewrite(f);
while ok=false do
      begin
      ok:=true;
      if i mod 2=1 then begin
                        write(f,chr(unu+96));
                        dec(v[unu]);
                        end
           else begin
                write(f,chr(doi+96));
                dec(v[doi]);
                end;
      inc(i);
      uu:=unu;
      if v[unu]=0 then unu:=doi+1;
      if ((v[doi]=0) and (v[uu]<>0)) then inc(doi)
         else if v[doi]=0 then inc(doi);
      for j:=1 to 26 do
          if v[j]<>0 then begin
                          ok:=false;
                          break
                          end;
      end;
close(f);
end.