求pascal 中,用栈写的四则运算是可以做运算的程序,加减乘除,括号一起

来源:百度知道 编辑:UC知道 时间:2024/09/26 13:26:38

别人都问过了,我就不复制别人的东西了,
这个网址,看看吧,
http://zhidao.baidu.com/question/56428040.html?fr=qrl&fr2=query

program stack;
var str:string;
function main(x:integer):longint;
var num:array [1..1000] of longint;
symbol:array [1..1000] of string[1];
ans,i,topn,tops,n,code:longint;
flag:boolean;
st:string;
begin
if x>length(str) then exit(0);
fillchar(num,sizeof(num),0);
topn:=0;
tops:=0;
ans:=0;
i:=x;
flag:=false;
while i<=length(str) do
begin
st:=copy(str,i,1);
if st='(' then
begin
topn:=topn+1;
num[topn]:=main(i+1);
code:=0;
for n:=i to length(str) do
begin
if (copy(str,n,1)='(') then code:=code+1
else if (copy(str,n,1)=')') then code:=code-1;
if code=0 then break;
e