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 Access Violation
Posted by Dilyan 8 May 2005 22:06
type el = ^t;
     t = record
          link : el;
          val : longint;
         end;


var a : array[0..2000] of pointer;
    i, j, k, l, o, m, n, pp1, pp2 : longint;
    p, q : el;
    s, s1, st, msg, p1, p2 : string;
    int : integer;
    f : text;


begin
 assign(f, '');
 reset(f);
 readln(f, n);
 for i := 1 to n do
   begin
    readln(f, s);
    msg := '';
    p1 := '';
    p2 := '';
    while s[1] <> ' ' do
      begin
       msg := msg + s[1];
       delete(s, 1, 1);
      end;
    while s[1] = ' ' do
      delete(s, 1, 1);
    while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do
      begin
       p1 := p1 + s[1];
       delete(s, 1, 1);
      end;
    if msg = 'PUSH' then
      begin
       while s[1] = ' ' do
         delete(s, 1, 1);
       while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do
         begin
          p2 := p2 + s[1];
          delete(s, 1, 1);
         end;
      end;
    val(p1, pp1, int);
    if msg = 'PUSH' then val(p2, pp2, int);
    if msg = 'POP' then
      begin
       p := a[pp1];
       writeln(p^.val);
       a[pp1] := p^.link;
      end
    else
      begin
       new(p);
       p^.val := pp2;
       p^.link := a[pp1];
       a[pp1] := p;
      end;
   end;
 close(f);
end.
Re: USE CHAR
Posted by Aybek Bukabayev 19 Feb 2006 13:02
I ALSO HAD THIS PROBLEM, YOU SHOULD USE CHAR NOT STRING

Dilyan wrote 8 May 2005 22:06
type el = ^t;
     t = record
          link : el;
          val : longint;
         end;


var a : array[0..2000] of pointer;
    i, j, k, l, o, m, n, pp1, pp2 : longint;
    p, q : el;
    s, s1, st, msg, p1, p2 : string;
    int : integer;
    f : text;


begin
 assign(f, '');
 reset(f);
 readln(f, n);
 for i := 1 to n do
   begin
    readln(f, s);
    msg := '';
    p1 := '';
    p2 := '';
    while s[1] <> ' ' do
      begin
       msg := msg + s[1];
       delete(s, 1, 1);
      end;
    while s[1] = ' ' do
      delete(s, 1, 1);
    while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do
      begin
       p1 := p1 + s[1];
       delete(s, 1, 1);
      end;
    if msg = 'PUSH' then
      begin
       while s[1] = ' ' do
         delete(s, 1, 1);
       while (s[1] >= '0') and (s[1] <= '9') and (s <> '') do
         begin
          p2 := p2 + s[1];
          delete(s, 1, 1);
         end;
      end;
    val(p1, pp1, int);
    if msg = 'PUSH' then val(p2, pp2, int);
    if msg = 'POP' then
      begin
       p := a[pp1];
       writeln(p^.val);
       a[pp1] := p^.link;
      end
    else
      begin
       new(p);
       p^.val := pp2;
       p^.link := a[pp1];
       a[pp1] := p;
      end;
   end;
 close(f);
end.