Pagini recente » Cod sursa (job #2585499) | Cod sursa (job #3145417) | Cod sursa (job #3256090) | Cod sursa (job #2324993) | Cod sursa (job #227820)
Cod sursa(job #227820)
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.