一道这么简单的模拟题 而我却不知道哪里有错误啊 求帮忙啊
ACM ZOJ Problem Set - 1056 真心无语 我不知道我代码哪里有错啊 求帮忙啊
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
using namespace std;
int map[51][51];
char s[101];
typedef struct Point
{
int x,y;
}point ;
point p[30];
int main()
{
int step;
while(1)
{
scanf("%d",&step);
if(step==0)break;
scanf("%s",s);
for(int i=1;i<51;i++)
for(int j=1;j<51;j++)
map[i][j]=0;
int sum=0;
point temp;
for(int i=11;i<=30;i++)
{
map[25][i]=1;
temp.x=25;
temp.y=i;
p[i-11]=temp;
}
int x,y;
temp=p[19];
int headx=temp.x;
int heady=temp.y;
for(int i=0;i<step;i++)
{
if(s[i]=='N')
{
x=headx-1;
y=heady;
}
else if(s[i]=='S')
{
x=headx+1;
y=heady;
}
else if(s[i]=='W')
{
x=headx;
y=heady-1;
}
else if(s[i]=='E')
{
x=headx;
y=heady+1;
}
if(x<=0||y<=0||x>=51||y>=51)
{
break;
}
else if(map[x][y]==1)
{
break;
}
else
{
sum++;
headx=x;
heady=y;
temp.x=x;
temp.y=y;
point t;
t=p[0];
map[t.x][t.y]=0;
map[x][y]=1;
for(int j=0;j<19;j++)
{
p[j]=p[j+1];
}
p[19]=temp;
}
}
if(sum==step)
printf("The worm successfully made all %d moves.\n",step);
else if(x>50||y>50||x<1||y<1)
{
printf("The worm ran off the board on move %d.\n",sum+1);
}
else printf("The worm ran into itself on move %d.\n",sum+1);
}
return 0;
}
temp.y=i;
p[i-11]=temp;
}
int x,y;
temp=p[19];
int headx=temp.x;
int heady=temp.y;
int f=0;
for(int i=0;i<step;i++)
{
if(s[i]=='N')
{
x=headx-1;
y=heady;
}
else if(s[i]=='S')
{
x=headx+1;
y=heady;
}
else if(s[i]=='W')
{
x=headx;
y=heady-1;
}
else if(s[i]=='E')
{
x=headx;
y=heady+1;
}
if(x<=0
[解决办法]
y<=0
[解决办法]
x>=51
[解决办法]
y>=51)
{
f=1;
break;
}
else if(map[x][y]==1)
{
if(x==p[0].x&&y==p[0].y)
f=3;
else
{f=2; break;}
}
if(f==3
[解决办法]
f==0)
{
sum++;
headx=x;
heady=y;
temp.x=x;
temp.y=y;
point t;
t=p[0];
map[t.x][t.y]=0;
map[x][y]=1;
for(int j=0;j<19;j++)
{
p[j]=p[j+1];
}
p[19]=temp;
}
}
if(sum==step)
printf("The worm successfully made all %d moves.\n",step);
if(f==1)
{
printf("The worm ran off the board on move %d.\n",sum+1);
}
if(f==2) printf("The worm ran into itself on move %d.\n",sum+1);
}
return 0;
}