ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1101. Robot in the Field

Why I Got WA ? Help , Thank you .
Posted by XueMao 12 Mar 2003 14:48
I used boolean Expression to deal with the it . I can not find where
is wrong in my code indeed. can anyone help me ?

Program Bolan;

Const h:array[0..4] of string=('(',')','OR','AND','NOT');
      g:array[1..4,1..2] of shortint=
      ((1,0),(0,-1),(-1,0),(0,1));
Type Lion=record
            Value,bj:Shortint;
          end;
     xm=array[0..5000] of Lion;

Var i,j,k,m,n,atop,btop,x,y,k1,k2,bak1:longint;
    code,direct:integer;
    s:string;
    c:char;
    a,bak:xm;
    b:array[0..5000] of longint;
    e:array[0..26] of longint;
    d:array[0..26,1..2] of longint;
    Turn:array[0..100,1..2] of longint;

Function Find(c:string):integer;
var i:integer;
begin
  for i:=0 to 4 do
  if h[i]=c then
  begin
    Find:=i;
    exit;
  end;
end;

Procedure Go(c:string);
var i,j:integer;
    d:char;
Begin
  j:=find(c);
  if btop=0 then
  begin
    inc(btop);
    b[1]:=j;
  end
  else
  begin
    if j=0 then
    begin
      inc(btop);
      b[btop]:=0;
    end
    else if (b[btop]=0)and(j=1) then dec(btop)
    else
    begin
      while (j<b[btop])and(btop>0) do
      begin
        inc(atop);
        a[atop].value:=b[btop];
        a[atop].bj:=b[btop];
        dec(btop);
      end;
      if (b[btop]=0)and(j=1)and(btop<>0) then dec(btop)
      else
      begin
        inc(btop);
        b[btop]:=j;
      end;
    end;
  end;
End;

Function Main:boolean;
var i,j:longint;
    bb:boolean;
Begin
  for i:=1 to atop do
  if a[i].bj=5 then a[i].value:=e[a[i].value];
  repeat
    bb:=true;
    for i:=1 to atop do
    if a[i].bj<5 then
    begin
      bb:=false;
      break;
    end;
    if not(bb) then
    begin
      case a[i].bj of
        2:a[i-2].value:=a[i-2].value or a[i-1].value;
        3:a[i-2].value:=a[i-2].value and a[i-1].value;
        4:a[i-1].value:=1-a[i-1].value;
      end;
      if a[i].bj=4 then
      begin
        a[i-1].bj:=6;
        move(a[i+1],a[i],(atop-i)*2);
        dec(atop);
      end
      else
      begin
        a[i-2].bj:=6;
        move(a[i+1],a[i-1],(atop-i)*2);
        dec(atop,2);
      end;
    end;
  until bb;
  if a[1].value=1 then Main:=true
  else Main:=false;
End;

Procedure Inside(s:string);
Begin
  while s[1]=' ' do delete(s,1,1);
  while s[Length(s)]=' ' do
  delete(s,length(s),1);
  if s='TRUE' then
  begin
    inc(atop);
    a[atop].value:=1;
    a[atop].bj:=6;
  end
  else if s='FALSE' then
  begin
    inc(atop);
    a[atop].value:=0;
    a[atop].bj:=6;
  end
  else if (s='OR')or(s='AND')or(s='NOT') then Go(s)
  else if (length(s)=1)and(ord(s[1])>64)
  and(ord(s[1])<91) then
  begin
    inc(atop);
    a[atop].value:=ord(s[1])-64;
    a[atop].bj:=5;
  end;
End;

Procedure Init;
Var i:longint;
    s:string;
    c:char;
Begin
  fillchar(a,sizeof(a),0);
  fillchar(e,sizeof(e),0);
  fillchar(b,sizeof(b),0);
  fillchar(turn,sizeof(turn),0);
  for i:=1 to 26 do
  begin
    d[i,1]:=maxlongint;
    d[i,2]:=maxlongint;
  end;
  s:='';
  atop:=0;
  btop:=0;
  while not(eoln) do
  begin
    read(c);
    if (c='(')or(c=')')or(c=' ') then
    begin
      if s<>'' then Inside(s);
      if (c='(')or(c=')') then go(c);
      s:='';
    end
    else s:=s+c;
  end;
  readln;
  if s<>'' then Inside(s);
  for i:=btop downto 1 do
  begin
    inc(atop);
    a[atop].value:=b[i];
    a[atop].bj:=b[i];
  end;
  btop:=0;
End;

Begin
  Init;
  readln(n,m,k);
  for i:=1 to m do
  readln(turn[i,1],turn[i,2]);
  for i:=1 to k do
  begin
    read(k1,k2);
    readln(s);
    while s[1]=' ' do delete(s,1,1);
    while s[Length(s)]=' ' do delete(s,length(s),1);
    j:=ord(s[1])-64;
    d[j,1]:=k1;
    d[j,2]:=k2;
  end;
  Direct:=1;
  x:=0;
  y:=0;
  while true do
  begin
    writeln(x,' ',y);
    for j:=1 to 26 do
    if (x=d[j,1])and(y=d[j,2]) then e[j]:=1-e[
Re: Why I Got WA ? Help , Thank you .
Posted by XueMao 12 Mar 2003 16:10
How foolish am I ! I actually thought that there is only one point
for one register , so I set the array  d:array[1..26,1..2] of integer
to record the Capital Letter's position . My God ! My English is
poor, but my IQ is even Poorer
Re: Why I Got WA ? Help , Thank you .
Posted by ahyangyi_newid 25 Sep 2005 09:44
I guess that you meant your English was nicer than your IQ ... :)