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

Обсуждение задачи 1027. Снова D++

why compilation error
Послано Илья Гофман (Ilya Gofman) 9 сен 2002 18:57
Here is my pascal solution.


program DPP_AGAIN;
var  mass,stack:array[1..10001] of char;
     kol,ls,i:integer;
     res,comment,cont:boolean;
function arithm:boolean;
begin
     if ((ord(mass[i])>=48) and (ord(mass[i])<=57)) or
        (mass[i]='/') or (mass[i]='*') or (mass[i]='+') or (mass[i]
='-')
          or (mass[i]='(') or (mass[i]='=') then
        arithm:=true else
        arithm:=false;
end;
begin
{     assign(input,'input.txt');
     reset(input);
     assign(output,'output.txt');
     rewrite(output);}
     fillchar(mass,sizeof(mass),#0);
     fillchar(stack,sizeof(stack),#0);
     kol:=0;
     ls:=0;
     res:=true;
     while not eof do
     begin
          while not eoln do
          begin
               inc(kol);
               read(mass[kol]);
          end;
          readln;
     end;
     for i:=1 to kol do
     begin
          if mass[i]='(' then
          begin
               {if begin of comment}
               if mass[i+1]='*' then
               begin
                    i:=i+2;
                    while (not ((mass[i]='*') and (mass[i+1]=')')))
and (i<=kol) do
                       inc(i);
                    if i>=kol+1 then
                       res:=false else
                    inc(i);
               end else
               {if begin of arithmetic expression}
               begin
                    comment:=false;
                    inc(i);
                    stack[1]:='(';
                    ls:=1;
                    cont:=true;
                    while cont do
                    begin
                         if (mass[i]='(') and (mass[i+1]='*') then
                         begin
                              comment:=true;
                              inc(i);
                         end;
                         if not comment then
                         begin
                              if mass[i]='(' then
                              begin
                                   inc(ls);
                                   stack[ls]:='(';
                              end;
                              if (mass[i]=')') then
                              begin
                                 if stack[ls]='(' then
                                   dec(ls) else
                                  res:=false;
                              end else
                              if not arithm then
                                 res:=false;
                         end;
                         if (mass[i]=')') and (mass[i-1]='*') then
                           comment:=false;
                         if (i>=kol) then
                           if (comment) or (ls>0) then
                              res:=false;
                         if (ls=0) or (i>=kol) then
                           cont:=false else
                           inc(i);
                    end;
               end;
          end else
          if mass[i]=')' then
            res:=false;
          if not res then
            i:=kol;
     end;
     if res then
       writeln('YES') else
       writeln('NO');
end.

I have the tests for this problem, and all of them work correct at
turbo pascal but i get compilation error here at delphi. any ideas?
Re: why compilation error
Послано IU712 8 ноя 2002 02:36
> Here is my pascal solution.
>
> {     assign(input,'input.txt');
>      reset(input);
>      assign(output,'output.txt');
>      rewrite(output);}

> I have the tests for this problem, and all of them work correct at
> turbo pascal but i get compilation error here at delphi. any ideas?

Use standard input and output (ReadLn, WriteLn). For you information:
in Delphi Assign should be written as AssignFile (Close=>CloseFile).
Re: why compilation error
Послано sun yi 20 дек 2002 07:32
I think the problem may be here:
for i:=1 to kol do
begin
 inc(i);
end;

Do not change the value of i while using "for"