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 i have crash?
Posted by Aybek Bukabayev 15 Feb 2006 19:10
type  pt=^p;
     p=record
          n:longint;
          next:pt;
     end;
var
   a:array[1..1000000]of pt;
   q,t:pt;
   s:string[4];
   n:longint;

procedure init;
var i,j:longint;
 begin
     readln(n);
     for i:=1 to n do
     begin
     read(s);
     if s='PUSH'then begin
         new(q);
         read(j);
         readln(q^.n);
         t:=a[j];
         a[j]:=q;
         a[j]^.next:=t;
         end else
     begin
         readln(j);
         writeln(a[j]^.n);
         a[j]:=a[j]^.next;
     end;
     end;
 end;
 begin

       init;
   end.

Edited by author 15.02.2006 19:11
Because FreePascal reads strings of limited length otherwise than Delphi does (+)
Posted by Michael Rybak (accepted@ukr.net) 15 Feb 2006 20:27
I don't have FP, so I can't tell how exactly.
Use the following code to get ML 10:

{s: string;}
c: char

...

{read(s);}
read(c, c, c, c);
{if s='PUSH' then begin}
if c='H' then begin

...
thank you but i have another problem ML test10
Posted by Aybek Bukabayev 16 Feb 2006 15:59
can i dispose q after using it once  and then again
new(q)
Michael Rybak (accepted@ukr.net) wrote 15 February 2006 20:27
I don't have FP, so I can't tell how exactly.
Use the following code to get ML 10:

{s: string;}
c: char

...

{read(s);}
read(c, c, c, c);
{if s='PUSH' then begin}
if c='H' then begin

...

Edited by author 16.02.2006 16:00
You can, but I think it wouldn't help for this problem (+)
Posted by Michael Rybak (accepted@ukr.net) 16 Feb 2006 18:05
In fact, it is good style to always dispose everything that you don't need.

Edited by author 16.02.2006 18:05
i have tried and got crash again i dont understand why
Posted by Aybek Bukabayev 16 Feb 2006 19:44
Michael Rybak (accepted@ukr.net) wrote 16 February 2006 18:05
In fact, it is good style to always dispose everything that you don't need.

Edited by author 16.02.2006 18:05
Post your code again then :) (-)
Posted by Michael Rybak (accepted@ukr.net) 16 Feb 2006 20:28
-
Re: DO YOU HAVE ANY IDEA TO DEC IT'S MEMORY
Posted by Aybek Bukabayev 19 Feb 2006 12:57
type  pt=^p;
     p=record
          n:longint;
          next:pt;
     end;
var
   a:array[1..1000]of pt;
   q:pt;
   s:char;
   n:longint;

procedure init;
var i,j:longint;
 begin
     readln(n);
     for i:=1 to n do
     begin
     read(s,s,s,s);
     if s='H'then begin
       new(q);
         read(j);
         readln(q^.n);
         q^.next:=a[j];
         a[j]:=q;
         a[j]^.next:=q^.next;
         end else
     begin
         readln(j);
         writeln(a[j]^.n);
         a[j]:=a[j]^.next;
     end;
     end;
 end;
 begin
         init;
   end.
I think you need a different approach for this problem (-)
Posted by Michael Rybak (accepted@ukr.net) 20 Feb 2006 14:02
-