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

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

I got WA at least 20 times, can anybody debug my program??
Послано Ural_Happy New Year! 8 июл 2003 15:53
program t1027;
var i,j,pp,n,k:longint;
    ch:char;
    str:array[1..10000] of char;
    t:boolean;
begin
     j:=1;
     while not eof do
           begin
           read(ch);
           str[j]:=ch;
       inc(j);
           end;
     n:=j-1; i:=0;
     repeat
         if str[i]=')' then begin writeln('NO'); halt; end;
         if not(str[i] in [')','(']) then inc(i);
         j:=i;
         if str[i]='(' then
            if str[i+1]='*' then
               begin
                    t:=false;
                    for j:=i+2 to n do if (str[j]='*')and(str[j+1]
=')') then
                        begin t:=true; break; end;
                    if t=false then begin writeln('NO'); halt; end
                       else i:=j+2;
                    j:=0;
               end
            else begin
                 inc(pp);
                 repeat
                       inc(j);
                       if not(str[j] in ['(',')','0'..'9','+','-
','*','/','='])
                          then begin writeln('NO'); halt; end;
                       if (str[j]='(')and(str[j+1]='*') then
                          begin
                          for k:=j+2 to n do
                              if (str[k]='*')and(str[k+1]=')') then
                                 begin j:=k+2; break; end;
                          if k>=n then begin writeln('NO'); halt; end;
                          end;
                       if str[j]=')' then dec(pp);
                       if pp=0 then break;
                       if str[j]='(' then inc(pp);
                 until j>=n;
                 if pp<>0 then begin writeln('NO'); halt; end;
                 i:=j+1;
                 end;
     until i>n;
     writeln('YES');

end.
I got AC! See my stubit bugs!
Послано Ural_Happy New Year! 14 июл 2003 16:08
> program t1027;
> var i,j,pp,n,k:longint;
>     ch:char;
>     str:array[1..10000] of char;
>     t:boolean;
> begin
>      j:=1;
>      while not eof do
>            begin
>            read(ch);
>            str[j]:=ch;
>        inc(j);
>            end;
>      n:=j-1; i:=0;
>      repeat
>          if str[i]=')' then begin writeln('NO'); halt; end;
>          if not(str[i] in [')','(']) then inc(i);
>          j:=i;
>          if str[i]='(' then
>             if str[i+1]='*' then
>                begin
>                     t:=false;
>                     for j:=i+2 to n do if (str[j]='*')and(str[j+1]
> =')') then
>                         begin t:=true; break; end;
>                     if t=false then begin writeln('NO'); halt; end
>                        else i:=j+2;
>                     j:=0;
>                end
>             else begin
>                  inc(pp);
>                  repeat
>                        inc(j);
>                        if not(str[j] in ['(',')','0'..'9','+','-
> ','*','/','='])<-----(#13,#10)
>                           then begin writeln('NO'); halt; end;
>                        if (str[j]='(')and(str[j+1]='*') then
>                           begin
                            (need to 'dec(pp)')
>                           for k:=j+2 to n do
>                               if (str[k]='*')and(str[k+1]=')') then
>                                  begin j:=k+2; break; end;
>                           if k>=n then begin writeln('NO'); halt;
end;
>                           end;
>                        if str[j]=')' then dec(pp);
>                        if pp=0 then break;
>                        if str[j]='(' then inc(pp);
>                  until j>=n;
>                  if pp<>0 then begin writeln('NO'); halt; end;
>                  i:=j+1;
>                  end;
>      until i>n;
>      writeln('YES');
> end.
>