记录编号 18625 评测结果 EWEWEEEWWW
题目名称 表达式转换 最终得分 0
用户昵称 Gravataritachi 是否通过 未通过
代码语言 Pascal 运行时间 0.003 s
提交时间 2010-09-16 21:30:32 内存使用 0.40 MiB
显示代码纯文本
 program a2;
 const
 fh:array[1..7,1..6]of char=(('<','<','<','<','<','>'),
                             ('<','<','<','<','<','>'),
                             ('>','>','<','<','<','>'),
                             ('>','>','<','<','<','>'),
                             ('>','>','>','>','<','>'),
                             ('>','>','>','>','>','>'),
                             ('<','<','<','<','<','T'));

 score:array['0'..'9']of integer=((0),(1),(2),(3),(4),(5),(6),(7),(8),(9));
 var
 f1,f2:text;
 ans:array[1..10000]of longint;
 stack:array[1..10000]of char;
 ch:char;
  i,head,mo:longint;
 data:set of char;
 memory:array[1..1000]of string;


 procedure deal(var head:longint);

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

   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],' ');
          inc(mo);
          memory[mo]:=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;

  procedure print;
  var
  code:longint;
  x,y,r,l:longint;
  i:longint;
  st:char;
  begin
  for i:= 1 to mo do
  if memory[i][1] in data
   then break;

   r:=i-1;
  while memory[r]='F' do dec(r);
  if r<>1 then l:=r-1 else exit;
  while memory[l]='F' do dec(l);
  val(memory[l],x,code);
  val(memory[r],y,code);
  case memory[i][1] of
   '+':str(x+y,memory[l]);
   '-':str(x-y,memory[l]);
   '*':str(x*y,memory[l]);
   '/':str(x div y,memory[l]);
   '^':str(round(exp(ln(x)*y)),memory[l]);
   end;
  memory[r]:='F';
  memory[i]:='F';
  writeln(f2);
  for i:= 1 to mo do
  if memory[i]<>'F' then write(f2,memory[i],' ');
  if memory[1]<>'F' then print;

  end;





 begin
 mo:=0;
 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],' ');
      inc(mo);
      str(ans[i],memory[mo]);
     end;
  end;
   if (head<>0)and(stack[head]<>')')and(stack[head]<>'(')
   then begin
        write(f2,stack[head]);
         inc(mo);
          memory[mo]:=stack[head];
        end;
close(f1);
print;
close(f2);

 end.