{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n \u003ccenter\u003e\n \u003cimg SRC\u003d\"CDN_BASE_URL/b5f7b6f7437179e2a7369804425b8270?v\u003d1534383667\"\u003e\n \u003c/center\u003e \n \u003cbr\u003eA robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are \n \u003cbr\u003e \n \u003cbr\u003eN north (up the page) \n \u003cbr\u003eS south (down the page) \n \u003cbr\u003eE east (to the right on the page) \n \u003cbr\u003eW west (to the left on the page) \n \u003cbr\u003e \n \u003cbr\u003eFor example, suppose the robot starts on the north (top) side of Grid 1 and starts south (down). The path the robot follows is shown. The robot goes through 10 instructions in the grid before leaving the grid. \n \u003cbr\u003e \n \u003cbr\u003eCompare what happens in Grid 2: the robot goes through 3 instructions only once, and then starts a loop through 8 instructions, and never exits. \n \u003cbr\u003e \n \u003cbr\u003eYou are to write a program that determines how long it takes a robot to get out of the grid or how the robot loops around. \n \u003cbr\u003e\n \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n There will be one or more grids for robots to navigate. The data for each is in the following form. On the first line are three integers separated by blanks: the number of rows in the grid, the number of columns in the grid, and the number of the column in which the robot enters from the north. The possible entry columns are numbered starting with one at the left. Then come the rows of the direction instructions. Each grid will have at least one and at most 10 rows and columns of instructions. The lines of instructions contain only the characters N, S, E, or W with no blanks. The end of input is indicated by a row containing 0 0 0.\n \u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\n \u003cdiv class\u003d\"ptx\" lang\u003d\"en-US\"\u003e\n For each grid in the input there is one line of output. Either the robot follows a certain number of instructions and exits the grid on any one the four sides or else the robot follows the instructions on a certain number of locations once, and then the instructions on some number of locations repeatedly. The sample input below corresponds to the two grids above and illustrates the two forms of output. The word \"step\" is always immediately followed by \"(s)\" whether or not the number before it is 1.\n \u003c/div\u003e"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e3 6 5\nNEESWE\nWWWESS\nSNWWWW\n4 5 1\nSESWE\nEESNW\nNWEEN\nEWSEN\n0 0 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre class\u003d\"sio\"\u003e10 step(s) to exit\n3 step(s) before a loop of 8 step(s)\n\u003c/pre\u003e"}},{"title":"","value":{"format":"HTML","content":"一个机器人已经被编程来跟随它在矩阵中的指令。矩阵中放置了机器人遇到的指令。可能的指令是\nN(向上)\nS(向下)\nE(向右)\nW(向左)\n例如,\n假设机器人从矩阵1的北(上)侧开始,开始向南(向下)。示出机器人跟随的路径。机器人在离开矩阵之前经过矩阵中的10条指令。\n矩阵2中发生的情况:机器人经过了3个格点后,然后开始一个8条指令的循环,并且永远不会退出。\n你要编写一个程序来判断一个机器人离开矩阵需要多长时间,或者机器人是如何循环的。"}},{"title":"","value":{"format":"HTML","content":"机器人将有一个或多个网格导航。每个数据的形式如下。第一行是由空格分开的三个整数:网格中的行数r、网格中的列数c和机器人从北方进入的列的数目p。可能的入口列被由1开始从左往右依次编号。然后,接下来r行输入矩阵。每个点的指令只包含字符N、S、E或W,没有空格。由一行0 0 0表示输入结束。数据约定1 \u003c\u003d r, c, p \u003c\u003d 10"}},{"title":"","value":{"format":"HTML","content":"对于输入中的每一个数据(矩阵),都有一行输出。无论是机器人遵循一定数量的指令然后从矩阵的任意一边退出,亦或是机器人遵循指令经过了一些点。下面的样例输入对应于上面的两个网格,并说明输出的两种形式。step一词始终使用复数\"steps\",无论在它之前的数字是不是1。"}}]}