Pagini recente » Cod sursa (job #3216227) | Cod sursa (job #2097937) | Cod sursa (job #2011802) | Cod sursa (job #533081) | Cod sursa (job #109694)
Cod sursa(job #109694)
Program Ordine;
var
s: string;
c: char;
i, j, l: LongInt;
cg: LongInt;
fin,fout:text;
Function Conflict(poz:LongInt):Boolean;
Begin
Conflict := False;
if poz>1 then if s[poz]=s[poz-1] then Conflict:=True;
if poz<length(s) then if s[poz]=s[poz+1] then Conflict:=True;
End;
begin
assign(fin,'ordine.in'); reset(fin);
assign(fout,'ordine.out'); rewrite(fout);
Readln(fin,s);
l:=length(s);
cg:=0;
repeat
for i:= l downto 2 do
begin
cg:=0;
For j:=1 to i-1 do
Begin
if (s[i]<s[j]) then
begin
c:=s[j];
s[j]:=s[i];
s[i]:=c;
inc(cg);
if conflict(i) or conflict(j) then
begin
c:=s[j];
s[j]:=s[i];
s[i]:=c;
dec(cg);
end;
end;
end;
end;
until cg=0;
writeln(fout,s);
close(fin);close(fout);
end.