You have a robot standing on the originXAxis. The robot will be given some instructions. Your task is to predict its position after executing all the instructions.
- Left: Move one unit left (DecreasePBy 1, wherePIs the position of the robot before moving)
- Right: Move one unit right (increasePBy 1)
- SameI: Perform the same action as inI-Th instruction. it is guaranteed thatIIs a positive integer not greater than the number of instructions before this.
Input
The first line contains the number of test casesT(T100). Each test case begins with an integerN(1N100), the number of instructions. Each of the followingNLines contains an instruction.
Output
For each test case, print the final position of the robot. Note that after processing each test case, the robot shocould be reset to the origin.
Sample Input
23LEFTRIGHTSAME AS 25LEFTSAME AS 1SAME AS 2SAME AS 1SAME AS 4
Sample output
1-5
Question
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <string> 5 using namespace std; 6 int T, n, ans; 7 string s[105]; 8 int main(){ 9 scanf("%d", &T);10 while(T--){11 ans = 0;12 string t;int temp;13 scanf("%d", &n);14 for(int i = 1; i <= n; i++){15 cin>>s[i];16 if(s[i][0] == ‘S‘){17 cin>>t;cin>>temp;18 s[i] = s[temp];19 }20 21 }22 for(int i = 1; i <= n; i++){23 if(s[i][0] == ‘R‘) ans++;24 else ans--; 25 }26 printf("%d\n", ans); 27 } 28 29 return 0;30 }