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

📄 ac1203.pas

📁 同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料
💻 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 + -