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

WHY CRASH???
Please, help! I'm so puzzled!
program dfx;
type
    PoinType = ^DynType;
    DynType = record
            inf: array[1..3] of longint;
            next: Pointype;
    end;
var
   point: array[1..1000] of pointype;
   l: array[1..1000] of byte;
   pr,pol: pointype;
   sn,p,q,i,n: longint;
   k: char;
begin
     readln(n);
     for q:=1 to n do
         point[q]:=nil;
     for q:=1 to n do
         begin
              read(k,k,k,k);
              if k = 'H'
                 then
                     begin
                          readln(sn,p);
                          inc(l[sn]);
                          if l[sn]>3
                             then
                                 begin
                                      l[sn]:=1;
                                      new(pol);
                                      pol^.inf[1]:=p;
                                      pol^.next:=point[sn];
                                      point[sn]:=pol;
                                 end
                             else
                                 point[sn]^.inf[l[sn]]:=p;
                     end
                 else
                     begin
                          readln(sn);
                          writeln(point[sn]^.inf[l[sn]]);
                          dec(l[sn]);
                          if l[sn]=0
                             then
                                 begin
                                      l[sn]:=3;
                          pr:=point[sn]^.next;
                          if point[sn]<>nil then
                          dispose(point[sn]);
                          point[sn]:=pr;
                                 end;
                     end;
         end;
end.