Why WA...?Could someone give me some tests...?Thanks.
Posted by
Mirror 6 Sep 2005 22:02
My Code:
program ural1008;
const
maxn=5;
turn:array[1..4] of integer=(maxn,1,-maxn,-1);
outp:array[1..4] of char=('R','T','L','B');
var
m,hash:array[1..maxn*maxn] of boolean;
q:array[1..maxn*maxn] of integer;
s:string;
procedure rep1;
var
i,k,n,a,b,l,r:integer;
begin
val(s,n,k);readln(a,b);writeln(a,' ',b);
m[maxn*(a-1)+b]:=true;l:=1;r:=1;
q[l]:=maxn*(a-1)+b;hash[q[l]]:=true;
for i:=2 to n do begin
readln(a,b);m[maxn*(a-1)+b]:=true;
end;
while l<=r do begin
for i:=1 to 4 do begin
a:=q[l]+turn[i];
if (a>0)and(a<=maxn*maxn) then
if (not hash[a])and(m[a]) then begin
write(outp[i]);inc(r);q[r]:=a;
hash[a]:=true;
end;
end;
if l<>r then writeln(',') else writeln('.');
inc(l);
end;
end;
procedure rep2;
var
i,a,b,k,l,r:integer;
s1,s2:string;
c:char;
begin
s1:='';i:=1;
while s[i]<>' ' do begin
s1:=s1+s[i];inc(i);
end;
s2:=copy(s,i+1,length(s)-i);
val(s1,a,k);val(s2,b,k);l:=1;r:=1;
q[l]:=maxn*(a-1)+b;hash[q[l]]:=true;
m[q[l]]:=true;
while l<=r do begin
read(c);if c='.' then break;
while c<>',' do begin
case c of
'R':a:=q[l]+turn[1];
'T':a:=q[l]+turn[2];
'L':a:=q[l]+turn[3];
'B':a:=q[l]+turn[4];
end;
if not hash[a] then begin
m[a]:=true;inc(r);q[r]:=a;
end;
read(c);if c='.' then break;
end;
if c='.' then break;
inc(l);readln;
end;
writeln(r);
for i:=1 to maxn*maxn do
if m[i] then writeln(i div maxn+1,' ',i mod maxn);
end;
begin
readln(s);
fillchar(m,sizeof(m),false);
fillchar(hash,sizeof(hash),false);
if length(s)<=2 then rep1
else rep2;
end.
Thank you very much!!