Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

为什么wa！！实在是无语了。。。

Posted by hustar at 2008-11-08 01:36:49 on Problem 1573
```#include <stdio.h>
#include <string.h>
int main()
{
int r, c, cntx, cnty, i, j, ans, flag;
int step[20][20];
char map[20][20];
while(scanf("%d%d%d%*c",&r,&c,&cnty)&&r)
{
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
map[i][j]=getchar();
getchar();
}
memset(step,0,sizeof(step));
ans=1;
cntx=1;
flag=0;
while(1)
{
switch(map[cntx][cnty])
{
case 'E': cnty++;break;
case 'W': cnty--;break;
case 'N': cntx--;break;
case 'S': cntx++;break;
}
if(!(cntx>=1&&cntx<=r&&cnty>=1&&cnty<=c)) break;
else if(step[cntx][cnty])
{
flag=1;
break;
}
else
{
ans++;
step[cntx][cnty]=ans;
}
}
if(flag)
printf("%d step(s) before a loop of %d step(s)\n",step[cntx][cnty]-1,ans-step[cntx][cnty]+1);
else printf("%d step(s) to exit\n",ans);
}
return 0;
}
```

Followed by:

User ID:
Title:

Content: