| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么wa!!实在是无语了。。。#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:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator