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

My program is said to use 753KB, but I don't think so.
Posted by Koala 29 Aug 2003 13:51
program p1220;

const
  maxn=100000;
  m=1000;

type
  indextype=record
    ind1,ind2,ind3:byte;
  end;

var
  value:array [1..maxn] of longint;
  pre:array [1..maxn] of indextype;
  top:array [1..m] of indextype;
  ppp,n,pp,i,k,x:longint;
  st:string;
  ch:char;

begin
  readln(ppp);
  n:=0;
  fillchar(top,sizeof(top),0);
  for pp:=1 to ppp do
  begin
    st:='';
    read(ch);
    while ch<>' ' do
    begin
      st:=st+ch;
      read(ch);
    end;
    if st='PUSH'
      then begin
        readln(i,x);
        inc(n); value[n]:=x;
        pre[n]:=top[i];
        k:=n;
        top[i].ind3:=k mod 256; k:=k div 256;
        top[i].ind2:=k mod 256; k:=k div 256;
        top[i].ind1:=k;
      end
      else begin
        readln(i);
        x:=top[i].ind1*256*256+top[i].ind2*256+top[i].ind3;
        writeln(value[x]);
        top[i]:=pre[x];
      end;
  end;
end.