pascal 字符串问题(递归算法)

来源:百度知道 编辑:UC知道 时间:2024/05/19 16:11:28
字符串s全部由0和1组合而成,但字符串s中有些位上的字符丢失了,只能用‘*’代替,如:100*1**01*0**1,现在要求对字符进行复原,编程输出S的所有可能。

最好有pascal的程序。

Program charlist;
var
s,c:string;
a:array [1..100] of integer;
i,j,l,counter:integer;
flag:boolean;
begin
readln(s);
l:=length(s);
counter:=0;
for i := 1 to l do
if s[i]='*' then
inc(counter);
repeat
j:=1;
for i := 1 to l do
if s[i]<>'*' then
write(s[i])
else
begin
write(a[j]);
inc(j)
end;
writeln;
inc(a[counter]);
for i := counter downto 1 do
if a[1]=2 then
begin
flag:=true;
break
end
else
if a[i]=2 then
begin
inc(a[i-1]);
a[i]:=0
end
else
break
until flag=true
end.