Pagini recente » Cod sursa (job #2057659) | Cod sursa (job #1592044) | Istoria paginii runda/ioi_training | Cod sursa (job #2011297) | Cod sursa (job #127936)
Cod sursa(job #127936)
program NOD_SOFTWARE;
var v,x:array [1..1000000] of char;
p,c:char;
point,i,j,n,m,poz,indice:longint;
fin,fout:text;
ok:boolean;
{*-----------------------*}
function cautare(c:char):longint;
var i:integer;
begin
cautare:=0;
for i:=1 to n do if v[i] = c then
begin
cautare:=i;
exit;
end;
end;
{*-----------MAIN---------*}
begin
assign(fin,'ordine.in'); reset(fin);
assign(fout,'ordine.out'); rewrite(fout);
n:=0;
while not eoln(fin) do
begin
inc(n);
read(fin,v[n]);
end;
indice:=0;
for p:='a' to 'z' do
begin
ok:=true;
while ((ok) and (cautare(p)>0)) do
begin
ok:=false;
poz:=cautare(chr(ord(p)-1));
if poz > 0 then
begin
if x[indice] = p then
begin
inc(indice);
x[indice]:=v[poz];
inc(indice);
x[indice]:=p;
end
else
begin
inc(indice);
x[indice]:=p;
inc(indice);
x[indice]:=v[poz];
end;
ok:=true;
v[poz]:='$'
end
else
begin
poz:=cautare(chr(ord(p)+1));
if poz > 0 then
begin
if x[indice] = p then
begin
inc(indice);
x[indice]:=v[poz];
inc(indice);
x[indice]:=p;
end
else
begin
inc(indice);
x[indice]:=p;
inc(indice);
x[indice]:=v[poz];
end;
v[poz]:='$';
ok:=true;
end;
end;
v[cautare(p)]:='$'
end;
end;
for i:=1 to indice do write(fout,x[i]);
close(fin);
close(fout);
end.