讨论 / wa40,请大牛查错
lxl 2011-09-25 10:23:00
点我顶贴 收藏 删除
var

s,s1,s2:ansistring;

a:array[0..1001] of longint;

i,j,k,l,m,n,p,q,r,x,y,z:longint;

begin

readln(n);

for i:=1 to n do

begin

readln(s);

if pos('(',s)=0 then begin writeln(s); continue; end;

fillchar(a,sizeof(a),0);

z:=0;

s1:=s;

j:=1;

while j<=length(s) do

begin

if s[j]='(' then begin inc(z); a[z]:=j; end;

if s[j]=')' then

begin

x:=ord(s[a[z]-1]);

y:=ord(s[j+1]);

if ((x<97) or (x>122)) and ((y<97) or (y>122)) and (x<>41) and (y<>40) then

begin

delete(s,a[z],1);

for k:=z downto 1 do if a[k]>=j then dec(a[k]) else break;

if j>length(s) then j:=length(s);

while s[j]<>')' do dec(j);

delete(s,j,1);

j:=0;

fillchar(a,sizeof(a),0);

z:=0;

//if j>length(s) then j:=length(s)-1;

end

else

begin

for k:=j downto a[z] do

if s[k]='+' then break

else

if k=a[z] then

begin

delete(s,a[z],1);

delete(s,j-1,1);

fillchar(a,sizeof(a),0);

j:=0; z:=0;

end;

end;

if z<>0 then

dec(z);

end;

inc(j);

end;

writeln(s);

end;

end.

查看更多回复
提交回复