ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1220. Stacks

i' v got TLE ontest #3. why?
Posted by SHXVACIKA 26 Oct 2004 01:52
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.