ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1220. Stacks

why i have crash?
Послано Aybek Bukabayev 15 фев 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 (+)
Послано Michael Rybak (accepted@ukr.net) 15 фев 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
Послано Aybek Bukabayev 16 фев 2006 15:59
can i dispose q after using it once  and then again
new(q)
Michael Rybak (accepted@ukr.net) писал(a) 15 февраля 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 (+)
Послано Michael Rybak (accepted@ukr.net) 16 фев 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
Послано Aybek Bukabayev 16 фев 2006 19:44
Michael Rybak (accepted@ukr.net) писал(a) 16 февраля 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 :) (-)
Послано Michael Rybak (accepted@ukr.net) 16 фев 2006 20:28
-
Re: DO YOU HAVE ANY IDEA TO DEC IT'S MEMORY
Послано Aybek Bukabayev 19 фев 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 (-)
Послано Michael Rybak (accepted@ukr.net) 20 фев 2006 14:02
-