Cod sursa(job #127936)
Utilizator | Data | 25 ianuarie 2008 15:10:21 | |
---|---|---|---|
Problema | Ordine | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 2.4 kb |
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.