⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1117.pas

📁 同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料
💻 PAS
字号:
program tju1117;
var
  m1:array['A'..'Z']of real;
  m2:array['A'..'Z','a'..'z']of real;
  n,i,p:longint;
  c1,c2:char;
  s:string;
  ans:real;
procedure cal(mul:longint);
  var
    x,e:longint;
  begin
    while s[p]<>'(' do begin
      if s[p] in ['0'..'9'] then begin
        x:=0;e:=1;
        repeat
          inc(x,(ord(s[p])-48)*e);
          e:=e*10;
          dec(p);
        until not (s[p] in ['0'..'9']);
      end
      else
        x:=1;
      if s[p]=')' then begin
        dec(p);cal(mul*x);dec(p);
      end
      else if s[p] in ['a'..'z'] then begin
        ans:=ans+m2[s[p-1],s[p]]*mul*x;dec(p,2);
      end
      else begin
        ans:=ans+m1[s[p]]*mul*x;dec(p);
      end;
    end;
  end;
begin
  repeat
    readln(n);
    for i:=1 to n do begin
      read(c1,c2);
      if c2=' ' then readln(m1[c1]) else readln(m2[c1,c2]);
    end;
    readln(n);
    for i:=1 to n do begin
      readln(s);
      write(s,' ');
      s:='('+s;
      p:=length(s);
      ans:=0;
      cal(1);
      if abs(round(ans)-ans)<1e-6 then writeln(round(ans)) else writeln(ans:0:3);
    end;
  until seekeof;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -