📄 ac1183.pas
字号:
program tju1183;
var
typ:array['a'..'z']of char;
int:array['a'..'z']of integer;
str:array['a'..'z']of string;
prog:array[1..999]of string;
t,u,n,l:word;
s:string;
buf:char;
function value(c:char):integer;
begin
if c>'9' then value:=int[c] else value:=ord(c)-48;
end;
procedure _read(c:char);
begin
if typ[c]='i' then begin
int[c]:=0;
repeat read(buf);until buf in ['0'..'9'];
repeat
int[c]:=int[c]*10+ord(buf)-48;
if eoln then begin buf:=chr(0);break;end;
read(buf);
until not (buf in ['0'..'9']);
end
else
if buf=chr(0) then
read(str[c])
else begin
read(s);
str[c]:=buf+s;
buf:=chr(0);
end;
end;
procedure _write(c:char);
begin
if typ[c]='i' then write(int[c]) else write(str[c]);
end;
begin
readln(t);
for u:=1 to t do begin
repeat
readln(s);
while s[1]=' ' do delete(s,1,1);
until s='var';
repeat
readln(s);
while s[1]=' ' do delete(s,1,1);
if s='begin' then break;
typ[s[1]]:=s[3];
until false;
n:=0;
repeat
readln(s);
while s[1]=' ' do delete(s,1,1);
if s='end.' then break;
inc(n);prog[n]:=s;
until false;
buf:=chr(0);
for l:=1 to n do
case length(prog[l]) of //Smart, isn't it?
5:int[prog[l,1]]:=value(prog[l,4]);
7:case prog[l,5] of
'+':int[prog[l,1]]:=value(prog[l,4])+value(prog[l,6]);
'-':int[prog[l,1]]:=value(prog[l,4])-value(prog[l,6]);
'*':int[prog[l,1]]:=value(prog[l,4])*value(prog[l,6]);
end;
8:_read(prog[l,6]);
9:_write(prog[l,7]);
10:begin _read(prog[l,8]);readln;buf:=chr(0);end;
11:begin _write(prog[l,9]);writeln;end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -