|
|
back to boardWA?? Posted by ufx 21 Apr 2003 05:24 program p1220; type tstack=^pnode; pnode=record data:longint; next:tstack; end;
var s:array[1..1000] of tstack; sy:string[4]; procedure push(a,b:integer); var p:tstack; begin p:=s[a]; while (p^.next<>nil) do p:=p^.next; new(p^.next); p:=p^.next; p^.data:=b; p^.next:=nil; end; procedure pop(a:integer); var p,q:tstack; begin p:=s[a]^.next; q:=s[a]; while (p^.next<>nil) do begin p:=p^.next;q:=q^.next end; q^.next:=nil; writeln(p^.data); dispose(p); end; procedure init; var i:integer; begin for i:=1 to 1000 do begin new(s[i]); s[i]^.data:=-1; s[i]^.next:=nil; end; end; var i,n:longint; a,b:integer; begin init; //assign(input,'in'); reset(input); readln(n); for i:=1 to n do begin read(sy); if sy='PUSH' then begin readln(a,b); push(a,b); end else begin readln(a); pop(a); end; end; end. |
|
|