|
|
back to boardi' v got TLE ontest #3. why? type Pstack = ^stack; stack = record l: longint; p: Pstack; end; brdzaneba = (PUSH,POP); var a: array [1..1000] of Pstack; b: array [1..1000] of longint; g: Pstack; i, j, n, k: integer; c: char; br: brdzaneba; stackNO: integer; v: longint; function PUSHorPOP:brdzaneba; var c: char; s :string[5]; begin read(c); s := ''; while c<>' ' do begin s := s+c; read(c); end; if s='PUSH' then PUSHorPOP := PUSH else PUSHorPOP := POP; end; procedure procPUSH; begin readln(stackNO,v); g := a[stackNO]; new(a[stackNO]); a[stackNO]^.l := v; a[stackNO]^.p := g; end; procedure procPOP; begin readln(stackNO); k := k+1; { writeln(a[stackNO]^.l);} b[k] := a[stackNO]^.l; a[stackNO] := a[stackNO]^.p; end; begin readln(n); for i := 1 to n do a[i] := nil; k := 0; for i := 1 to n do begin if PUSHorPOP = PUSH then procPUSH else procPOP; end; for i := 1 to k do writeln(b[i]); end. |
|
|