标签:des style blog http io ar color os sp
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> int move[4][2]={{0,1},{0,-1},{-1,0},{1,0}}; int turn(char w) { if(w==‘N‘) return 2; if(w==‘E‘) return 0; if(w==‘S‘) return 3; return 1; } int main() { char grid[100][100]; int m,n,x,y,tx,ty,start_N; while(scanf("%d%d",&m,&n)!=EOF){ int book[100][100]={0}; if(m==0&&n==0) return 0; scanf("%d",&start_N); int step=0,loop,flag=0; for(int i=0;i<m;i++) scanf("%s",grid[i]); x=0,y=start_N-1; while(1){ if(x==0&&y==start_N-1&&book[x][y]==0) book[x][y]=1; tx=x+move[turn(grid[x][y])][0]; ty=y+move[turn(grid[x][y])][1]; if(tx>=m||ty>=n||tx<0||ty<0){ step=book[x][y]; flag=1; break; } else if(book[tx][ty]!=0){ step=book[tx][ty]-1; loop=book[x][y]-step; flag=2; break; } book[tx][ty]=book[x][y]+1; x=tx,y=ty; } if(flag==1) printf("%d step(s) to exit\n",step); else printf("%d step(s) before a loop of %d step(s)\n",step,loop); } return 0; }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/yanglingwell/p/4116654.html