PersonalCorpus 版 (精华区)

277650 07:57:38 15 Nov 2002 Big Guava
1220 Pascal Accepted 0.56 sec 606K

program p1220_3;

var
    i,j,k,m,n,t:integer;
    last:array[1..1000] of integer;
    b:array[1..100000] of word;
    c:array[1..100000] of integer;
    s:string[100];


begin

{$IFNDEF ONLINE_JUDGE}
    assign(input,'input1220.txt');reset(input);
    assign(output,'output1220.txt');rewrite(output);
{$ENDIF}

    readln(n); t:=0;
    for i:=1 to n do begin
        readln(s);
        if pos('PUSH',s)<>0 then begin
            inc(t);
            k:=0;
            j:=pos('PUSH',s)+4; while s[j]=' ' do inc(j);
            while s[j]<>' ' do begin
                k:=10*k+ord(s[j])-48;
                inc(j);
            end;
            last[k]:=t;
            b[t]:=k;
            k:=0; m:=length(s);
            while s[j]=' ' do inc(j);
            while (j<=m) and (s[j]<>' ') do begin
                k:=10*k+ord(s[j])-48;
                inc(j);
            end;
            c[t]:=k;
        end else begin
            k:=0; m:=length(s);
            j:=pos('POP',s)+3; while s[j]=' ' do inc(j);
            while (j<=m) and (s[j]<>' ') do begin
                k:=10*k+ord(s[j])-48;
                inc(j);
            end;
            for j:=last[k] downto 1 do if b[j]=k then break;
            last[k]:=j-1;
            b[j]:=0;
            writeln(c[j]);
        end;
    end;
end.
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.245毫秒