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

Обсуждение задачи 1102. Странный диалог

Who can help me?I use graph and search from the end,but WA.
Послано kkkkk 30 июл 2004 19:59
const letter:set of char=['a'..'z'];
      max=100000;
var n,t,l,e:longint;
    c:char;
    q,start:boolean;
    s:string;
    sz:array[1..max]of 0..4;{0:space;1:on;2:put;3:out;4:in}
begin
     readln(n);
     for t:=1 to n do
         begin
              fillchar(sz,sizeof(sz),0);
              q:=true;
              start:=true;
              l:=0;
              s:='';
              e:=0;
              while not eoln do
                    begin
                         read(c);
                         if c in letter then
                            begin
                                 start:=false;
                                 s:=s+c;
                                 inc(l);
                                 if l>=6 then
                                    begin
                                         q:=false;
                                         break;
                                    end;
                                 if s='e' then
                                    begin
                                         if sz[e]=1 then
                                            begin
                                                 l:=0;
                                                 s:='';
                                                 sz[e]:=0;
                                                 dec(e);
                                            end
                                                    else
                                            begin
                                                 q:=false;
                                                 break;
                                            end;
                                    end
                                          else
                                 if (l=2)or(l=3) then
                                 begin
                                    if s='on' then
                                       begin
                                            l:=0;
                                            s:='';
                                            inc(e);
                                            sz[e]:=1;
                                       end
                                              else
                                       if s='put' then
                                          begin
                                               l:=0;
                                               s:='';
                                               inc(e);
                                               sz[e]:=2;
                                          end
                                                  else
                                          if s='out' then
                                             begin
                                                  l:=0;
                                                  s:='';
                                                  inc(e);
                                                  sz[e]:=3;
                                             end
                                                     else
                                             if s='in' then
                                                begin
                                                     l:=0;
                                                     s:='';
                                                     inc(e);
                                                     sz[e]:=4;
                                                end;
                                 end;
                            end
                                         else
                            if not start then
                               begin
                                    q:=false;
                                    break;
                               end;
                    end;
              if l<>0 then
                 q:=false;
              l:=e;
              if q then
              while l>0 do
                    begin
                    if (sz[l]=4)or(sz[l]=3) then
                       begin
                            l:=l-1;
                       end
                                            else
                       if sz[l]=2 then
                          begin
                               if (sz[l-1]=4)or(sz[l-1]=3) then
                                  l:=l-2
                                                           else
                                  begin
                                       q:=false;
                                       break;
                                  end;
                          end
                                  else
                          if sz[l]=1 then
                             begin
                                  if sz[l-1]=2 then
                                     l:=l-2
                                               else
                                     begin
                                          q:=false;
                                          break;
                                     end;
                             end;
                      end;
              readln;
              if q then
                 writeln('YES')
                   else
                 writeln('NO');
         end;
end.