记录编号 12611 评测结果 AAAAAAAAAA
题目名称 表达式转换 最终得分 100
用户昵称 Gravatar.Xmz 是否通过 通过
代码语言 Pascal 运行时间 0.000 s
提交时间 2009-09-15 19:31:25 内存使用 0.17 MiB
显示代码纯文本
program xmz;
var
 x:string;
 st1:array[0..1000]of char;
 st2:array[0..1000]of char;
 st:array[1..1000]of int64;
 xx:array['('..'^']of integer;
 t:char;
 f1,f2:text;
 h1,h2,a,h,b:integer;
 s:int64;
procedure ru(ch:char);
 begin
  if ch=')' then
  begin
  while st2[h2]<>'('do
  begin
   h1:=h1+1;
   st1[h1]:=st2[h2];
   dec(h2);
  end;
  dec(h2);
  end
  else
  if not((xx[ch]>xx[st2[h2]])or(ch='('))or(ch=st2[h2]) then
  while xx[st2[h2]]>=xx[ch] do
  begin
   h1:=h1+1;
   st1[h1]:=st2[h2];
   dec(h2);
  end;
  if ch<>')' then begin h2:=h2+1;st2[h2]:=ch;end;
 end;
begin
 assign(f1,'express.in');assign(f2,'express.out');
 reset(f1);rewrite(f2);
 xx['+']:=1;xx['-']:=1;xx['*']:=2;xx['/']:=2;xx['^']:=3;xx['(']:=0;xx[')']:=0;
 xx['.']:=0;st2[0]:='.';
 read(f1,x);
 for a:=1 to length(x) do
  begin
   t:=x[a];
   if ('0'<=t)and(t<='9') then begin h1:=h1+1;st1[h1]:=t; end
   else ru(t);
  end;

  while h2>0 do
  begin
   h1:=h1+1;
   st1[h1]:=st2[h2];
   dec(h2);
  end;

 for a:=1 to h1-1 do
  write(f2,st1[a],' ');
  write(f2,st1[h1]);

 for a:=1 to h1 do
  begin
    if ('0'<=st1[a])and(st1[a]<='9') then begin h:=h+1;st[h]:=ord(st1[a])-48; end
    else begin
          h:=h-1;
          s:=st[h];
          if st1[a]='+' then st[h]:=st[h]+st[h+1];
          if st1[a]='-' then st[h]:=st[h]-st[h+1];
          if st1[a]='*' then st[h]:=st[h]*st[h+1];
          if st1[a]='/' then st[h]:=st[h] div st[h+1];
          if st1[a]='^' then for b:=1 to st[h+1]-1 do st[h]:=st[h]*s;
          writeln(f2);
          for b:=1 to h do write(f2,st[b],' ');
          for b:=a+1 to h1 do write(f2,st1[b],' ');
         end;
  end;
 close(f1);close(f2);
end.