记录编号 |
12614 |
评测结果 |
AAAAAAAAAA |
题目名称 |
表达式转换 |
最终得分 |
100 |
用户昵称 |
ybh |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.002 s |
提交时间 |
2009-09-15 21:01:27 |
内存使用 |
0.16 MiB |
显示代码纯文本
program BiaoDaShiDeZhuanHuan;
var
shu:array[1..100] of string;
fu:array[1..100] of string;
next,last:array[0..100] of integer;
st:string;
tops,topf,i,p,code,p1,p2:integer;
shu1,shu2,shu3:longint;
bool:boolean;
procedure zhuanhuan(s:string);
var
k,code:integer;
begin
repeat
if s[1] in ['0'..'9'] then
begin
tops:=tops+1;
shu[tops]:=s[1];
delete(s,1,1);
end
else
begin
case s[1] of
'*','/':
begin
if fu[topf]='*' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='/' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='^' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
topf:=topf+1;
fu[topf]:=s[1];
delete(s,1,1)
end;
'(':
begin
topf:=topf+1;
fu[topf]:=s[1];
delete(s,1,1)
end;
')':
begin
repeat
if fu[topf]='*' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='/' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='+' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='-' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='^' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
until (fu[topf]='(') or (topf=2);
topf:=topf-1;
delete(s,1,1)
end;
'+','-':
begin
repeat
if fu[topf]='*' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='/' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='+' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='-' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='^' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
until (fu[topf]='(') or (fu[topf]='#');
topf:=topf+1;
fu[topf]:=s[1];
delete(s,1,1)
end;
'#':
begin
repeat
if fu[topf]='*' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='/' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='+' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='-' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
if fu[topf]='^' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
until topf=1;
delete(s,1,1)
end;
'^':
begin
if fu[topf]='^' then
begin
tops:=tops+1;
topf:=topf-1;
shu[tops]:=fu[topf+1];
end;
topf:=topf+1;
fu[topf]:=s[1];
delete(s,1,1)
end
end
end
until s=''
end;
begin
assign(input,'express.in');
reset(input);
assign(output,'express.out');
rewrite(output);
readln(st);
st:=st+'#';
fu[1]:='#';
topf:=1;
tops:=0;
zhuanhuan(st);
for i:=1 to tops do
begin
write(shu[i],' ');
next[i]:=i+1;
last[i]:=i-1
end;
next[0]:=1;
last[tops+1]:=tops;
writeln;
repeat
p:=next[0];
if (shu[p]='+') or (shu[p]='-') or (shu[p]='*') or (shu[p]='/') or (shu[p]='^')
then bool:=false
else bool:=true;
while bool do
begin
p:=next[p];
if (shu[p]='+') or (shu[p]='-') or (shu[p]='*') or (shu[p]='/') or (shu[p]='^')
then bool:=false
else bool:=true;
end;
p1:=last[last[p]];
p2:=last[p];
val(shu[p1],shu1,code);
val(shu[p2],shu2,code);
case shu[p,1] of
'+':shu3:=shu1+shu2;
'-':shu3:=shu1-shu2;
'*':shu3:=shu1*shu2;
'/':shu3:=shu1 div shu2;
'^':
begin
shu3:=1;
for i:=1 to shu2 do
shu3:=shu3*shu1
end
end;
str(shu3,shu[p]);
next[last[last[last[p]]]]:=p;
last[p]:=last[last[last[p]]];
p:=next[0];
repeat
write(shu[p],' ');
p:=next[p]
until p=tops+1;
writeln;
until next[next[0]]=tops+1;
close(input);
close(output)
end.