hoang vi
Phan1 {Hoan vi}
var
s:string;
function next (A:string):string;
var
n,i,j:integer;
c:char;
begin
n:=length (s);
i:=n-1;
while ((i>0) and (a[i]>a[i+1])) do i:=i-1;
if i=0 then next:='!'
else
begin
j:=n;
while a[j]<a[i] do
j:=j-1;
c:=a[i];
a[i]:=a[j];
a[j]:=c;
for j:=i+1 to (n+i+1)div 2 do
begin
c:=a[j];
a[j]:=a[n+i+1-j];
a[n+i+1-j]:=c;
end;
next:=A;
end;
end;
begin
write('nhap s=');
readln(s);
while (s<> '!') do
begin
write(s:8);
s:= next(s);
end;
readln;
end.
-----------------------------------------------------------------
//phan 2
var
s:string;
function next (A:string):string;
var
n,i,j:integer;
c:char;
begin
n:=length (s);
i:=n-1;
while ((i>0) and (a[i]>a[i+1])) do i:=i-1;
if i=0 then next:='!'
else
begin
j:=n;
while a[j]<a[i] do
j:=j-1;
c:=a[i];
a[i]:=a[j];
a[j]:=c;
for j:=i+1 to (n+i+1)div 2 do
begin
c:=a[j];
a[j]:=a[n+i+1-j];
a[n+i+1-j]:=c;
end;
next:=A;
end;
end;
begin
write('nhap s=');
readln(s);
while (s<> '!') do
begin
write(s:8);
s:= next(s);
end;
readln;
end.
Bạn đang đọc truyện trên: AzTruyen.Top