讨论 / wa40,请大牛查错
lxl 2011-09-25 10:54: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.

#1 lxl@2011-09-25 10:52:00
回复 删除
连乘没有考虑

测试结果3: 测试结果错误.错误结果为:u(x+q)(y+s)(z+gf+lfp+h+q+r+r+n+xu)+q+e

(d+s+t+hs+f+f+z+pf+dlaz+xf+f+el(yqoj+t+e+etjgq+q+bqk))(r+(ssoqow+du+d+hf)k)

z

e(c(x+p+b))jl+b+tax(k+r+i)+qw+sh+bx+dy+z+w+svqd+xr [color=red]false![/color]

n+wcy+if+k+q+ltk+tp+l+k+y+f

m

(k(y+dth+vp+b+k+s+h))s(m+b)+kunw+nqh+(a+q)ngw+za

r(w+l+z+he+h)

e+f+tt+rp+g+(n+ov)e+a+g+aa+lt+zo+vn+brbgps+l+fb+v+k+p+f+a+e

i

m(xah+aoy)+hit(k(b+p+t+t)+f+voj+vba)

e+h+kj+l

l+ks+j+p+q(c+i)+q+xq+r+u((y+z)ianx)((w+lq)(j+v)y)h+vn+st+w+k

wdl+opq+u+x+gl+j+wo

w(s+i+h+h+b+x+q+r+(c+h)ekc)+wzh

dx+y+bcodu+n+(v+u)g

aj+flj+y+y(fi+s)+tn+c(mf+u+m)iv+xy

e

nzvud

s+e

d(z(n+t+adu)(p+a)iibb+e+n)

axk+o+us+t+rw+k

a

h((ah+br)(lj+i+u))+wzyufw+gr+nje+v+t+g+ebf+x+bz+syf+q+h+qu+nji+to

o

xg

f

z

正确结果应为:u(x+q)(y+s)(z+gf+lfp+h+q+r+r+n+xu)+q+e

(d+s+t+hs+f+f+z+pf+dlaz+xf+f+el(yqoj+t+e+etjgq+q+bqk))(r+(ssoqow+du+d+hf)k)

z

ec(x+p+b)jl+b+tax(k+r+i)+qw+sh+bx+dy+z+w+svqd+xr

n+wcy+if+k+q+ltk+tp+l+k+y+f

m

k(y+dth+vp+b+k+s+h)s(m+b)+kunw+nqh+(a+q)ngw+za

r(w+l+z+he+h)

e+f+tt+rp+g+(n+ov)e+a+g+aa+lt+zo+vn+brbgps+l+fb+v+k+p+f+a+e

i

m(xah+aoy)+hit(k(b+p+t+t)+f+voj+vba)

e+h+kj+l

l+ks+j+p+q(c+i)+q+xq+r+u(y+z)ianx(w+lq)(j+v)yh+vn+st+w+k

wdl+opq+u+x+gl+j+wo

w(s+i+h+h+b+x+q+r+(c+h)ekc)+wzh

dx+y+bcodu+n+(v+u)g

aj+flj+y+y(fi+s)+tn+c(mf+u+m)iv+xy

e

nzvud

s+e

d(z(n+t+adu)(p+a)iibb+e+n)

axk+o+us+t+rw+k

a

h(ah+br)(lj+i+u)+wzyufw+gr+nje+v+t+g+ebf+x+bz+syf+q+h+qu+nji+to

o

xg

f

z

测试结果4: 测试结果错误.错误结果为:yig+tr+i+(s+i)bj+t+u+rp+b(m+p+i+d+o+ls+l)+djl+jc+zrpotm+x

f

u

u(ql+og+jz)+o+fo

b+tbn+b+p+fsfhp+mmdt+ysb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xwxj+ct(i+e)+q)+i+(q+i+c)lb

v

hwl+u+g+e+n+gpf+l+r+j+ah+m+x+k+p+uc+sl+dv+e+lstg+do+xx+f+t+o+m+g+z+v(c+l)(h+u+k+x+l+o)pek

k+u+f

(jr+p+hoh+w)bv+vg+rf+r+f+ga+d

h

fzh

yv+mf+ro+tfhbi+j+gnq+y+i+nx

r+wgs+k+kl+lx+oh+nqb+r+m+ozu(p+h)

i+c

(e+k(q+o)+hz+zzjjbpf)dv+egl+wd+ip+h+a(t+bk)+lifqk+tw+l+v+m+jctg+d+mp(k+qn+v+x)+r+pn

r

x+(u+jyt)nyhqo+pr+kyi+v(p+f+g+pzjb)+k+o+e

u

j

w

s+f+wi

b+(ex+jct)c+j

q+b+i+n+q(m+d)+v(y+f)k+j(f+g)+(yta+e+m)a+d+o+gax+sj+v+wwwfej

g+t+u+x

on+eu+vq+t+v+rlg+c+c+b+xqj+clr

l+b

l+u(yh+a(w+d)c)evr+xshe+owej+v+gs

q

awm(j+zko)+e+gxwu+i+vt+z+(at+h)(v+gyqcfifo)

j+cid+g+qip+lh+mzl+dmnp+m+n+kqin(q+ye+v+mq+qp+tdhzx+(b+to+xna)(p+y+hb+p)qf(y+i+l)f)

ab+x+pohx+rb+f+o+(u+m)ha+d+w+d+ol+v+ccha+l+z+q+o+hy+r+dj+m+o+wov+o+d(a+a+e)t

vspiw+rc+my+qa+p+c+((ab+a)o+ib)z+gf+t+y+c+a+m+zv+q+a+x+zff+tr+f+xhk+v

测试结果5: 测试结果错误.错误结果为:t

gy

p+f

(vhee+n+i+fxfq+x+uff+ug+v+m)(mm(o+g)+y+bux+l+nmufa)+p+walf+a+f

e+j

ww+c

s

q

h+l+w(bdb+fg+tpgek)+q+(g+q)((n+b)nc)(oc+c+n)+s+h+x [color=red]false![/color]

o

g+q+t(g+h)l+cg+r

v(c+ra+f+t+fr+kbk+l)+h

gl

b

e+a+o+n+z+n+oi+xyc(r+b+f+w)hr+l

np+s

g+o

yp

q+(uvr+g+ajlq+xvh+f)(h+v)+y+h+(edw+s+sij)p

p

w+v+bxspm+ya+pd+nixl(h+q)+j+u+q+fm+(otj+f+t+z+d+lz)v+(g+h)f+rm+or+k(h+w)bw+s+ip+kapr

(xxllwtt+o+r+r+e+d+goz+y+if+i+o+ggv+q+o)(j+g(k+d)(l+w)(kslb+o)+iqikc)+(s+w+deg)a+c+m+dee

b

ub+l+d+yg+l+qzf+(p+c)wh+ev+(e+z+mn+jk+s+p)((mc+x+w)qhj+u)s+oedoom+v+hbpuxy+r+i+icqj+q+or+uv+e+flp

v+wz+vf+y+g+dtj+xgy+n+j(i+pte+i)+w+i+f+g+p+k+v+l+(p+x)bd+mc(k+e)or+k+h+w+p+ygl+hf+pd+btb+(c+m)a+a+gup+b

x

hn

k

g

abc

正确结果应为:t

gy

p+f

(vhee+n+i+fxfq+x+uff+ug+v+m)(mm(o+g)+y+bux+l+nmufa)+p+walf+a+f

e+j

ww+c

s

q

h+l+w(bdb+fg+tpgek)+q+(g+q)(n+b)nc(oc+c+n)+s+h+x

o

g+q+t(g+h)l+cg+r

v(c+ra+f+t+fr+kbk+l)+h

gl

b

e+a+o+n+z+n+oi+xyc(r+b+f+w)hr+l

np+s

g+o

yp

q+(uvr+g+ajlq+xvh+f)(h+v)+y+h+(edw+s+sij)p

p

w+v+bxspm+ya+pd+nixl(h+q)+j+u+q+fm+(otj+f+t+z+d+lz)v+(g+h)f+rm+or+k(h+w)bw+s+ip+kapr

(xxllwtt+o+r+r+e+d+goz+y+if+i+o+ggv+q+o)(j+g(k+d)(l+w)(kslb+o)+iqikc)+(s+w+deg)a+c+m+dee

b

ub+l+d+yg+l+qzf+(p+c)wh+ev+(e+z+mn+jk+s+p)((mc+x+w)qhj+u)s+oedoom+v+hbpuxy+r+i+icqj+q+or+uv+e+flp

v+wz+vf+y+g+dtj+xgy+n+j(i+pte+i)+w+i+f+g+p+k+v+l+(p+x)bd+mc(k+e)or+k+h+w+p+ygl+hf+pd+btb+(c+m)a+a+gup+b

x

hn

k

g

abc

#2 lxl@2011-09-25 10:54:00
回复 删除
怎么改

How can I correct this program?

RT

查看更多回复
提交回复