Hunan Province University student Program design contest original question B

Source: Internet
Author: User

B-Instructions for the robotTime limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld &%ll U Submit Status Practice CSU 1112

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

Sample Output



The Chinese question does not explain, the flood question does not explain

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineMAXN 100005#defineINF 0x3f3f3f3fintMain () {intT; intN; inta[ the]; Charstr[ -]; CIN>>T;  while(cin>>N) {intsum=0;  for(intI=0; i<n;i++) {scanf ("%s", str); if(str[0]=='L') {A[i+1]=-1; Sum-=1; }            Else if(str[0]=='R') {A[i+1]=1; Sum+=1; }            Else            {                intT; scanf ("%s", str); scanf ("%d",&t); A[i+1]=A[t]; Sum+=a[i+1]; }} cout<<sum<<Endl; }    return 0;}

Hunan Province University student Program design contest original question B

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.