满意答案
zjwandy2010
2014.09.16
采纳率:41% 等级:12
已帮助:5892人
var c:char; sym:array[0..30]of char; num:array[0..30]of longint; ts,tn:shortint; x:longword; procedure calcu; var p:char; x,x2:longint; x1:real; begin p:=sym[ts];dec(ts); x2:=num[tn];dec(tn); x1:=num[tn];dec(tn); case p of '+':x:=trunc(x1)+x2; '-':x:=trunc(x1)-x2; '*':x:=trunc(x1)*x2; '/':x:=trunc(x1) div x2; '^':x:=trunc(exp(x2*ln(x1))); end; if tn<0 then inc(tn); //判负 inc(tn);num[tn]:=trunc(x); end; procedure push; begin inc(ts);sym[ts]:=c; read(c); end; begin fillchar(num,sizeof(num),0); ts:=0;tn:=0; read(c); while not eoln do case c of '0'..'9':begin x:=0; repeat x:=x*10+ord(c)-ord('0'); read(c); until not(c in['0'..'9']); inc(tn);num[tn]:=x; end; '+','-':begin while(ts>0)and(sym[ts]<>'(')do calcu; push; end; '*','/':begin while(ts>0)and(sym[ts]in['*','/','^'])do calcu; push; end; '^':begin while(ts>0)and(sym[ts]='^')do calcu; push; end; '(':push; ')':begin while(sym[ts]<>'(')do calcu; dec(ts);read(c); end; end; if c in['0'..'9']then begin inc(tn);num[tn]:=ord(c)-ord('0'); end else if c=')' then begin while(sym[ts]<>'(')do calcu; dec(ts);read(c); end; while sym[ts]='(' do dec(ts); while ts>0 do calcu; writeln(num[1]); end. //pascal语言的
00分享举报