比赛 20100914 评测结果 WWWWWWWWWE
题目名称 表达式转换 最终得分 0
用户昵称 itachi 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-09-14 22:18:08
显示代码纯文本
 program a2;
 const
 fh:array[1..7,1..6]of char=(('<','<','<','<','<','>'),
                             ('<','<','<','<','<','>'),
                             ('>','>','<','<','<','>'),
                             ('>','>','<','<','<','>'),
                             ('>','>','>','>','<','>'),
                             ('>','>','>','>','>','>'),
                             ('<','<','<','<','<','T'));


 var
 f1,f2:text;
 ans:array[1..10000]of longint;
 stack:array[1..10000]of char;
 ch:char;
  i,head:integer;
 data:set of char;
 procedure deal(var head:integer);

  function num(x:char):integer;
   begin
     case x of
     '+':num:=1;
     '-':num:=2;
     '*':num:=3;
     '/':num:=4;
     '^':num:=5;
     '(':num:=6;
     ')':num:=7;
     end;
   end;
  procedure check(var head:integer);

   begin

    case fh[num(ch),num(stack[head-1])] of
    '>':stack[head]:=ch;
    '<':begin
          while (head>1) and(fh[num(ch),num(stack[head-1])]='<') do
          begin
          write(f2,stack[head-1],' ');
          dec(head);
          end;
              if head>1 then   begin
              if fh[num(ch),num(stack[head-1])]='>'
                 then
                 stack[head]:=ch;
               if fh[num(ch),num(stack[head-1])]='T' then head:=head-2;
               end
               else stack[head]:=ch;

        end;
    'T': head:=head-2;
    end;
   end;
  begin
  if head = 1
     then stack[head]:=ch
     else
     begin
      check(head);
     end;
  end;
 begin
 data:=['+']+['-']+['/']+['*']+['^']+['(']+[')'];
 assign(f1,'express.in');
 assign(f2,'express.out');
 reset(f1);
 rewrite(f2);
 i:=0;
 head:=0;
 while  not eof(f1) do
  begin
  read(f1,ch);
  if ch in data
     then
     begin
     inc(head);
     deal(head);

     end
     else
     begin
      inc(i);
      case ch of
       '0':ans[i]:=0;
       '1':ans[i]:=1;
       '2':ans[i]:=2;
       '3':ans[i]:=3;
       '4':ans[i]:=4;
       '5':ans[i]:=5;
       '6':ans[i]:=6;
       '7':ans[i]:=7;
       '8':ans[i]:=8;
       '9':ans[i]:=9;
       end;
      write(f2,ans[i],' ');
     end;
  end;
   if (head<>0)and(stack[head]<>')')and(stack[head]<>'(') then write(f2,stack[head]);
close(f1);
close(f2);


 end.