题目
求值后缀表达式 3 5*6 7+11/ -
提问时间:2020-11-03
答案
program hzbds_1010;
type stack=record
data:array[1..100] of real;
top:0..100;
end;
var s:stack;
ch:char;
i:integer;
x:real;
a:array[1..10] of char;
function pop(var s:stack):real; {enter}
begin
pop:=s.data[s.top];
s.top:=s.top-1;
end;
procedure push(var s:stack;x:real); {out}
begin
s.top:=s.top+1;
s.data[s.top]:=x;
end;
{main}
begin
i:=0;
repeat
i:=i+1;
read(a[i]);
until a[i]='@';
s.top:=0;
i:=1;
ch:=a[i];
while ch'@'do
begin
case ch of
'0'..'9':begin
x:=0;
while ch' 'do
begin
x:=x*10+ord(ch)-ord('0');
i:=i+1;
ch:=a[i];
end;
end;
'+':x:=pop(s)+pop(s);
'-':begin x:=pop(s);x:=pop(s)-x; end;
'*':x:=pop(s)*pop(s);
'/':begin x:=pop(s);x:=pop(s)/x; end;
end;
push(s,x);
i:=i+1;ch:=a[i];
end;
writeln(trunc(pop(s)));
end.
用pascal 运行一下注意结尾用@来结束输入
type stack=record
data:array[1..100] of real;
top:0..100;
end;
var s:stack;
ch:char;
i:integer;
x:real;
a:array[1..10] of char;
function pop(var s:stack):real; {enter}
begin
pop:=s.data[s.top];
s.top:=s.top-1;
end;
procedure push(var s:stack;x:real); {out}
begin
s.top:=s.top+1;
s.data[s.top]:=x;
end;
{main}
begin
i:=0;
repeat
i:=i+1;
read(a[i]);
until a[i]='@';
s.top:=0;
i:=1;
ch:=a[i];
while ch'@'do
begin
case ch of
'0'..'9':begin
x:=0;
while ch' 'do
begin
x:=x*10+ord(ch)-ord('0');
i:=i+1;
ch:=a[i];
end;
end;
'+':x:=pop(s)+pop(s);
'-':begin x:=pop(s);x:=pop(s)-x; end;
'*':x:=pop(s)*pop(s);
'/':begin x:=pop(s);x:=pop(s)/x; end;
end;
push(s,x);
i:=i+1;ch:=a[i];
end;
writeln(trunc(pop(s)));
end.
用pascal 运行一下注意结尾用@来结束输入
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
最新试题
热门考点
- 1三项220V,用电功率是8KW,需要用多少平方的电?请提供计算方式,
- 2一个梯形高于两底的乘积分别是13平方米,16.2平方米,这个梯形的面积是多少平方米?
- 3作文:令人难忘的读书经历
- 4X/30+X/40=1这个方程怎么解?
- 52012年地球会发生什么变化了大神们帮帮忙
- 6CAD里的矩形的标高是什么意思
- 7六年级的《穷人》中桑娜为什么非要把邻居的两个孩子抱回家?
- 8直线y=ex+b(e为自然对数的底数)与两个函数f(x)=ex,g(x)=lnx的图象至多有一个公共点,则实数b的取值范围是 _.
- 9我问外公:“这不是您最宝贵的画吗?”变为间接引语.怎么变呢?谢谢
- 10用托盘天平称量药品,托盘上的砝码为5克,游码在0.4克的位置上,指针指向最右端,所称药品的质量是( ) A.5.4克 B.不足5.4克 C.超过5.4克 D.4.6克