作业帮 > 综合 > 作业

program kuohao; type a=array[1..100]of char; var x:string; y

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 14:04:52
program kuohao; type a=array[1..100]of char; var x:string; y,i,s,top:integer; b,t:a; begin top:=0;
program kuohao;
type a=array[1..100]of char;
var x:string; y,i,s,top:integer; b,t:a;
begin
top:=0; i:=1; s:=0;
readln(x);
y:=length(x);
repeat
if x[i]='(' then begin
top:=top+1;
b[top]:=x[i];
end;
if x[i]=')' then begin
s:=s+1;
t[s]:=x[i];
end;
inc(i);
until i>y;
if top>s then writeln('< is more');
if topy;
if top>s then writeln('< is more');
if top
注意 else 的用法,程序读入的是字符串,如果你只是判定'('和')'那么遇到这种情况就不可以 (12353425)那中间的数字12353425你的程序只能读入一个1
然后就去判断下一个反括号,而第二个程序是else 即,读入的字符不是'('就执行下一步
s:=s+1;
t[s]:=x[i];
即else 是包含s[i]=')'和其他非'('字符的情况