| ||||||||||
| 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 | |||||||||
Re:where and when break?In Reply To:where and when break? Posted by:BlackieKing at 2011-12-12 18:36:55 #include<iostream>
using namespace std;
int main()
{int spot[2][20];
int x=0, y=1, i,n=19, times, movex=0, movey=0, correcttimes=0,key=0;
char directions;
LOOP:
while(cin>>times)
{if(times==0)
{break;
}
for(i=19;i>-1;i--)
{spot[x][i]=25;
spot[y][i]=30-i;
}
for(i=0;i<times;i++)
{
cin>>directions;
switch(directions)
{case 'E':movex=0 ; movey=1 ;break;
case 'W':movex=0 ; movey=-1 ;break;
case 'N':movex=-1 ; movey=0 ;break;
case 'S':movex=1 ; movey=0 ;break;
}
for(n=19;n>=1;n--)
{spot[x][n]=spot[x][n-1];
spot[y][n]=spot[y][n-1];
}
spot[x][0]+=movex;
spot[y][0]+=movey;
for(n=19;n>0;n--)
{if(spot[x][0]==spot[x][n]&&spot[y][0]==spot[y][n])
{key=2;break;
}
}
if(key==2)
{cout<<"The worm ran into itself on move "<<i+1<<"."<<endl;
key=0;
break;
}
if(spot[x][0]<1||spot[x][0]>50||spot[y][0]<1||spot[y][0]>50)
{cout<<"The worm ran off the board on move "<<i+1<<"."<<endl;
break;
}
if(i==times-1)
{cout<<"The worm successfully made all "<<times<<" moves."<<endl;
break;
}
}
}
system("pause");
return 0;
}
测试数据:
18
NWWWWWWWWWWSESSSWS
20
SSSWWNENNNNNWWWWSSSS
30
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
13
SWWWWWWWWWNEE
0
但是在输完20这组数据 就会跳出,
重新输30的数据也会跳出,
但是输18的可以到达输20的地方···
求神牛解释···
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator