楼上判断不了((())的情况(即左右不等)
var
ch:char;
left,right:longint; //其实像楼上只用一个num也行...两个看着方便
ans:boolean;
begin
left:=0;
right:=0;
ans:=true;
repeat
read(ch);
if ch='(' then inc(left);
if ch=')' then inc(right);
if r>left then
begin
ans:=false;
break;
end;
until ch='#';
readln;
if leftright then ans:=false;
writeln(ans);
readln;
end.
左括号个数随时都要大于右括号个数,且最后个数要相等
已调过,望采纳~