Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
其实楼下很多数据根本没有必要,实际数据不会有左右括号不等或者末尾多加号减号等等RT 只需要判断(前不是-就去掉,(A)这种形式也去掉,就可以AC了。 参考代码:供神牛BS: var f:array[0..255]of integer; s,str:string; ch:char; p,i,j,t:longint; begin readln(t); for i:=1 to t do begin readln(str); s:='+'; for j:=1 to length(str) do if str[j]<>' ' then s:=s+str[j]; fillchar(f,sizeof(f),0); p:=0; for j:=2 to length(s) do begin if s[j]='(' then begin inc(p); if (s[j-1]='+')or(s[j-1]='(') then f[p]:=j; end; if s[j]=')' then begin if f[p]<>0 then begin s[f[p]]:='~'; s[j]:='~'; end; f[p]:=0; dec(p); end; end; str:=''; for j:=2 to length(s) do if s[j]<>'~' then str:=str+s[j]; s:=str; for j:=2 to length(s) do if (s[j-1]='(')and(s[j+1]=')')and(s[j] in ['A'..'Z']) then begin s[j-1]:='~'; s[j+1]:='~'; end; for j:=1 to length(s) do if s[j]<>'~' then write(s[j]); writeln; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator