PersonalCorpus 版 (精华区)
44698 2002-10-22 21:17:33 Accepted
1056 C++ 00:00.00 380K Big Guava
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\zju\\i1056","r",stdin);
freopen("c:\\0acm\\zju\\o1056","w",stdout);
#endif
int i,j,k,m,n;
int a[20][2];
char s[110],*pp="EWNS";
static int p[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
while (1) {
scanf("%d\n",&n);
if (n==0) break;
gets(s);
for (i=0;i<20;i++) { a[i][0]=25; a[i][1]=i+11; }
j=19;
for (i=0;s[i]>0;i++) {
k=j+1; if (k==20) k=0;
for (m=0;m<4;m++) if (pp[m]==s[i]) break;
a[k][0]=a[j][0]+p[m][0];
a[k][1]=a[j][1]+p[m][1];
for (m=0;m<20;m++) if (m!=k)
if ((a[m][0]==a[k][0])&&(a[m][1]==a[k][1])) break;
if (m!=20) {
printf("The worm ran into itself on move %d.\n",i+1);
break;
}
if
((a[k][0]==0)||(a[k][0]==51)||(a[k][1]==0)||(a[k][1]==51)) {
printf("The worm ran off the board on move %d.\n",i+1);
break;
}
j=k;
}
if (s[i]==0) printf("The worm successfully made all %d moves.
\n",n);
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.086毫秒