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

Обсуждение задачи 1186. Chemical Reactions

Why I get wrong?
Послано sunshine 5 сен 2002 15:38
I did it like this:
Why I get wrong?

type
  td=array[1..26,0..26]of integer;
  tt=record
    a,b:integer;
    x:array[1..2]of integer;
    xi:integer;
    ty:integer;
    d:td;
  end;
var
  s1,s2:string;
  i,n:integer;
  d1,d2:td;
  t:array[1..50]of ^tt;
procedure turn(s:string;var d:td);
  var
    i,o,p:integer;
    k:integer;
  begin
    k:=1;
    new(t[k]);
    fillchar(t[k]^,sizeof(t[k]^),0);
    t[k]^.x[1]:=1;
    t[k]^.x[2]:=1;
    s:=s+'.';
    for i:=1 to length(s) do
      begin
        with t[k]^ do
          begin
            if s[i] in ['(',')','.','A'..'Z','+'] then
              begin
                if ty=1
                  then d[a,b]:=d[a,b]+x[1]*x[2];
                if ty=2
                  then begin
                    for o:=1 to 26 do
                      for p:=0 to 26 do
                        d[o,p]:=d[o,p]+t[k+1]^.d[o,p]*x[2]*x[1];
                    dispose(t[k+1]);
                  end;
                x[1]:=1;
                xi:=0;
              end;
            case s[i] of
              'A'..'Z':begin
                ty:=1;
                a:=byte(s[i])-byte('A')+1;
                b:=0;
              end;
              'a'..'z':begin
                b:=byte(s[i])-byte('a')+1;
              end;
              '0'..'9':begin
                if xi=0 then
                  begin
                    if a=0
                      then xi:=2
                      else xi:=1;
                    x[xi]:=byte(s[i])-byte('0');
                  end
                  else x[xi]:=x[xi]*10+byte(s[i])-byte('0');
              end;
              '(':begin
                ty:=2;
                inc(k);
                new(t[k]);
                fillchar(t[k]^,sizeof(t[k]^),0);
                t[k]^.x[1]:=1;
                t[k]^.x[2]:=1;
              end;
              ')':begin
                dec(k);
              end;
              '+':begin
                a:=0;
                b:=0;
                x[1]:=1;
                x[2]:=1;
                xi:=0;
                ty:=0;
              end;
            end;
          end;
      end;
    delete(s,length(s),1);
    d:=t[k]^.d;
  end;
function bj(var d1,d2:td):boolean;
  var
    i,j:integer;
  begin
    for i:=1 to 26 do
      for j:=0 to 26 do
        if d1[i,j]<>d2[i,j] then
          begin
            bj:=false;
            exit;
          end;
    bj:=true;
  end;
begin
  readln(s1);
  turn(s1,d1);
  readln(n);
  for i:=1 to n do
    begin
      readln(s2);
      turn(s2,d2);
      if bj(d1,d2)
        then writeln(s1,'==',s2)
        else writeln(s1,'!=',s2)
    end;
end.
Re: Why I get wrong?
Послано linchuan 8 сен 2002 13:14
I don't know!!!
>
> type
>   td=array[1..26,0..26]of integer;
>   tt=record
>     a,b:integer;
>     x:array[1..2]of integer;
>     xi:integer;
>     ty:integer;
>     d:td;
>   end;
> var
>   s1,s2:string;
>   i,n:integer;
>   d1,d2:td;
>   t:array[1..50]of ^tt;
> procedure turn(s:string;var d:td);
>   var
>     i,o,p:integer;
>     k:integer;
>   begin
>     k:=1;
>     new(t[k]);
>     fillchar(t[k]^,sizeof(t[k]^),0);
>     t[k]^.x[1]:=1;
>     t[k]^.x[2]:=1;
>     s:=s+'.';
>     for i:=1 to length(s) do
>       begin
>         with t[k]^ do
>           begin
>             if s[i] in ['(',')','.','A'..'Z','+'] then
>               begin
>                 if ty=1
>                   then d[a,b]:=d[a,b]+x[1]*x[2];
>                 if ty=2
>                   then begin
>                     for o:=1 to 26 do
>                       for p:=0 to 26 do
>                         d[o,p]:=d[o,p]+t[k+1]^.d[o,p]*x[2]*x[1];
>                     dispose(t[k+1]);
>                   end;
>                 x[1]:=1;
>                 xi:=0;
>               end;
>             case s[i] of
>               'A'..'Z':begin
>                 ty:=1;
>                 a:=byte(s[i])-byte('A')+1;
>                 b:=0;
>               end;
>               'a'..'z':begin
>                 b:=byte(s[i])-byte('a')+1;
>               end;
>               '0'..'9':begin
>                 if xi=0 then
>                   begin
>                     if a=0
>                       then xi:=2
>                       else xi:=1;
>                     x[xi]:=byte(s[i])-byte('0');
>                   end
>                   else x[xi]:=x[xi]*10+byte(s[i])-byte('0');
>               end;
>               '(':begin
>                 ty:=2;
>                 inc(k);
>                 new(t[k]);
>                 fillchar(t[k]^,sizeof(t[k]^),0);
>                 t[k]^.x[1]:=1;
>                 t[k]^.x[2]:=1;
>               end;
>               ')':begin
>                 dec(k);
>               end;
>               '+':begin
>                 a:=0;
>                 b:=0;
>                 x[1]:=1;
>                 x[2]:=1;
>                 xi:=0;
>                 ty:=0;
>               end;
>             end;
>           end;
>       end;
>     delete(s,length(s),1);
>     d:=t[k]^.d;
>   end;
> function bj(var d1,d2:td):boolean;
>   var
>     i,j:integer;
>   begin
>     for i:=1 to 26 do
>       for j:=0 to 26 do
>         if d1[i,j]<>d2[i,j] then
>           begin
>             bj:=false;
>             exit;
>           end;
>     bj:=true;
>   end;
> begin
>   readln(s1);
>   turn(s1,d1);
>   readln(n);
>   for i:=1 to n do
>     begin
>       readln(s2);
>       turn(s2,d2);
>       if bj(d1,d2)
>         then writeln(s1,'==',s2)
>         else writeln(s1,'!=',s2)
>     end;
> end.