IBMOA #67
Rover Move
估计简单可在线判题
考点(AI 标注)模拟/实现
The rover starts at the top-left corner of an n×n grid and moves one cell at a time according to UP, DOWN, LEFT and RIGHT. A command that would take it outside the grid is ignored, and the following commands still run. Return the final cell number row*n+column, with rows and columns numbered from 0.
输入格式
The first line contains n m, followed by m commands. Full original bounds: 2≤n≤20, 1≤m≤20; commands are only UP, DOWN, LEFT and RIGHT.
输出格式
Output one integer, the answer.
样例 1
输入:
4 6
RIGHT
UP
DOWN
LEFT
DOWN
DOWN
输出:
12
样例 2
输入:
2 4
LEFT
UP
RIGHT
RIGHT
输出:
1
样例 3
输入:
3 4
DOWN
DOWN
DOWN
RIGHT
输出:
7
样例说明
The outputs of the three public examples are, in order: 12; 1; 7. These answers were verified by independent enumeration or direct simulation.