Welcome to CSU Online judge!
1112: Instruction of the robot time limit: 1 Sec Memory Limit: MB
Submit: 274 Solved: 97
[Submit] [Status] [Web Board] Description
There is a robot at the origin of the axis. The robot will execute a series of instructions, and your task is to predict its location after all instructions have been executed.
· Left: Move one unit
· Right: Move one unit
· Same as I: performs the same action as article I. Input guarantee I is a positive integer and does not exceed the number of previous execution instructions
Input
Enter the number of first behavior Data group T (t<=100). The first behavior of each set of data is the integer n (1<=n<=100), which is the number of instruction strips. One instruction per line below. The instructions are numbered 1~n in order of entry.
Output
For each set of data, the final position of the robot is output. After each set of data is processed, the robot should be reset to the origin of the axis.
Sample Input
23LEFTRIGHTSAME as 25LEFTSAME as 1SAME as 2SAME as 1SAME as 4
Sample Output
1-5
HINT
Source
The computer program design competition of the university students in Hunan province
Last night we carried out the third simulation training, do is the province of 12, the end of our team only made 2 questions, hey, at night looked at the rank version of the year, almost fast is the countdown, still not ah, there are two questions can see what algorithm, but do not know how to make up, did not get out, To some of the algorithm did not reach the point of flexible use, or to refuel ah, this problem, yesterday began as if our team to do out, to this input or output should pay attention to AH.
This problem to note is its input, we use the segmented input, as if they do not have segmented input, we have a, maybe last night this problem luck is good;
The following is the code for AC:
#include <iostream> #include <cstring> #include <cstdio>using namespace Std;char s[10],c[10];int a[ 100];int Main () { int t,n,m; scanf ("%d", &t); while (t--) { int sum=0; memset (A,0,sizeof (a));//note here to clear 0 scanf ("%d", &n); for (int i=0;i<n;i++) { cin>> s; if (s[0]== ' L ') a[i]--; if (s[0]== ' R ') a[i]++; if (s[0]== ' s ') { cin>>c;//Note here is a three-stage input; cin>>m; A[I]=A[M-1]; } } for (int i=0;i<n;i++) sum+=a[i];//accumulates each time the information printf ("%d\n", sum); } return 0;}