| ||||||||||
| 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<memory.h>
int loop, out, row,col;
char map[12][12];
int step[12][12];
bool isok(int i,int j)
{
if(i>=0&&i<row&&j>=0&&j<col&&!step[i][j])
return true;
else
if(step[i][j])
{
loop=out-step[i][j]+1;
out-=loop;
}
return false;
}
void func(int i,int j)
{
switch (map[i][j])
{
case 'N':
if (isok(i-1,j))
{
out++;
step[i-1][j]=step[i][j]+1;
func(i-1,j);
}
break;
case 'W':
if (isok(i,j-1))
{
out++;
step[i][j-1]=step[i][j]+1;
func(i,j-1);
}
break;
case 'E':
if (isok(i,j+1))
{
out++;
step[i][j+1]=step[i][j]+1;
func(i,j+1);
}
break;
case 'S':
if (isok(i+1,j))
{
out++;
step[i+1][j]=step[i][j]+1;
func(i+1,j);
}
break;
}
}
int main()
{
int stand;
int i,j;
scanf("%d%d%d",&row,&col,&stand);
while(row!=0&&col!=0)
{
loop=0;
out=1;
memset(step,0,sizeof(int));
for(i=0;i<row;++i)
scanf("%s",map[i]);
step[0][stand-1]=1;
func(0,stand-1);
if(loop)
printf("%d step(s) before a loop of %d step(s)\n",out,loop);
else
printf("%d step(s) to exit\n",out);
scanf("%d%d%d",&row,&col,&stand);
}
return(0);
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator