早教吧作业答案频道 -->其他-->
求值后缀表达式35*67+11/-
题目详情
求值后缀表达式 3 5*6 7+11/ -
▼优质解答
答案和解析
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 运行一下注意结尾用@来结束输入
看了 求值后缀表达式35*67+1...的网友还看了以下:
近几年我国人口状况及政策的变化说明了()年份201220132014201515-59岁人口占总人 2020-04-07 …
这几道数量关系题谁会做?(1)12,4,8,6,7,()(2)0,1,1,2,4,7,13,()( 2020-05-17 …
《从岩缝里长出来的小草》读后感开头:中心(名言,好词.好句)开始写:1,主要内容2,针对文章谈感受 2020-07-07 …
100万元利息5个点(5个点的意思是5%),计算出来的月利息为4166.67元算法?5%/12=0 2020-07-17 …
说出下面各题简便计算的根据1.142+54+58+46=(142+58)+(54+46)2.2.4 2020-07-18 …
求比值并化简比16:204.5:67分之3:11分之6 2020-07-18 …
(2013•朝阳)“植草种树,防风治沙”.某地今年植草种树36700公顷,数据36700用科学记数 2020-08-03 …
以下面数据为例,固定资产净值如何计算?资产名称:打印机购入日期:2007.11.8原价:4000折旧 2020-11-18 …
关于英语请教1.什么叫单词的前缀?2.什么叫单词的后缀?3.什么叫单词的词根?本人是初学者,也不觉得 2020-12-10 …
常见食物pH的近似值范围如下:常见食物橘子汁泡菜酸牛奶鸡蛋清pH(近似值)3.0~4.03.2~3. 2020-12-14 …