Pascal全排列

来源:百度知道 编辑:UC知道 时间:2024/05/29 05:35:28
帮我看看这个程序有什么问题

program qpl;
var s,t:string;
n:integer;
function ch(p:integer):boolean;
var ii:integer;
begin
ch:=true;
for ii:=1 to p-1 do if t[ii]=t[p] then begin
ch:=false;
break;
end;
end;
procedure print(l:integer);
var i:integer;
begin
if l=n then writeln(t)
else begin
for i:=1 to n do begin
t[l]:=s[i];
if ch(l) then print(l+1);
end;
end;
end;
begin
assign(input,'qpl.in');
assign(output,'qpl.out');
reset(input);
rewrite(output);
readln(s);
n:=length(s);
print(1);
close(input);
close(output);
end.
楼下的,input和output是没问题的,但是我输入abc没输出。

打印有问题
不能直接打印
应该
if l>n then //不是l=n 要多做一次
begin
for i:=1 to n do
write(t[i]);
writeln;
end
else
******

assign(input,'qpl.in');
assign(output,'qpl.out');
reset(input);
rewrite(output);

我不知道这样写有没有问题。我一般是这样写的:
assign(input,'qpl.in');
reset(input);
assign(output,'qpl.out');
rewrite(output);

如果读进来的s的长度是1,那么一开始,t是没有赋值的,所以没有输出。
我建议单独处理一下,即:
if n=1 then writeln(s) else print(1);