Robot Instructions
12503_RobotInstructions
User Manual:
Open the PDF directly: View PDF .
Page Count: 1
Download | |
Open PDF In Browser | View PDF |
You have a robot standing on the origin of x axis. The robot will be given some instructions. Your task is to predict its position after executing all the instructions. • LEFT: move one unit left (decrease p by 1, where p is the position of the robot before moving) • RIGHT: move one unit right (increase p by 1) • SAME AS i: perform the same action as in the i-th instruction. It is guaranteed that i is a positive integer not greater than the number of instructions before this. Input The first line contains the number of test cases T (T ≤ 100). Each test case begins with an integer n (1 ≤ n ≤ 100), the number of instructions. Each of the following n lines contains an instruction. Output For each test case, print the final position of the robot. Note that after processing each test case, the robot should be reset to the origin. Sample Input 2 3 LEFT RIGHT SAME AS 5 LEFT SAME AS SAME AS SAME AS SAME AS 2 1 2 1 4 Sample Output 1 -5
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Page Count : 1 Creator : XeTeX output 2015.03.01:1350 Producer : xdvipdfmx (20140317) Create Date : 2015:03:01 13:50:25+01:00EXIF Metadata provided by EXIF.tools