📄 ac1203.pas
字号:
program tju1203;
const
maxcoms=100;
maxlinenum=3000;
type
command=record op,vari:char;num,go,next:word;end;
//op saves the second char of the command
varlist=array['A'..'Z']of word;
var
com:array[1..maxcoms]of command;
pos:array[0..maxlinenum]of byte;
lim,v:varlist;
last:array[1..maxcoms]of varlist;
coms,n,i,now:longint;
c:char;
begin
repeat
fillchar(pos,sizeof(pos),0);
fillchar(lim,sizeof(lim),0);
coms:=0;
repeat
read(n);
if n<0 then break;
inc(coms);pos[n]:=coms;
with com[coms] do begin
read(c,c,op);
case op of
'+':begin vari:=c;read(num);end;
'O':read(go);
'F':begin
read(c,vari,c,num,c,c,c,go);
if num>lim[vari] then lim[vari]:=num;
end;
'N':readln;
end;
end;
until false;
for c:='A' to 'Z' do inc(lim[c]);
n:=maxlinenum;while pos[n]=0 do dec(n);now:=1;
for i:=n-1 downto 0 do
if pos[i]>0 then
with com[pos[i]] do begin
next:=pos[n];n:=i;
if op in ['O','F'] then go:=pos[go];
end;
fillchar(v,sizeof(v),0);
fillchar(last,sizeof(last),255);
now:=pos[n];n:=0;
repeat
inc(n);
with com[now] do
case op of
'+':begin
inc(v[vari],num);
if v[vari]>lim[vari] then v[vari]:=lim[vari];
now:=next;
end;
'?':now:=next;
'O':now:=go;
'F':begin
if comparebyte(last[now],v,sizeof(v))=0 then begin n:=-1;break;end;
last[now]:=v;
if v[vari]=num then now:=go else now:=next;
end;
'N':break;
end;
until false;
writeln(n);
until seekeof;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -