Robot Instructions 

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 thati is a positive integer not greater than the number of instructions before this.

Input

The first line contains the number of test cases  T  ( T100 ). Each test case begins with an integer  n  (   1n100 ), 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 2
5
LEFT
SAME AS 1
SAME AS 2
SAME AS 1
SAME AS 4

Sample Output

1
-5
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
int t,n,p,a[105];
char s[10];
cin>>t;
while(t--)
{
p=0;
cin>>n;
getchar();
for(int i=1;i<=n;i++)
{
gets(s);
if(strlen(s)==4)
a[i]=-1;
else if(strlen(s)==5)
a[i]=1;
else if(!isdigit(s[strlen(s)-2]))
a[i]=a[s[strlen(s)-1]-'0'];
else
a[i]=a[s[strlen(s)-1]-'0'+10*(s[strlen(s)-2]-'0')];
p+=a[i];
}
cout<<p<<endl;
}
return 0;
}

12503 - Robot Instructions的更多相关文章

  1. [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]

      Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given som ...

  2. Robot Instructions

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  4. Notes on how to use Webots, especially how to make a robot fly in the air

    How to create a new project Wizard - New project directory   Scene Tree Scene tree is a representati ...

  5. Robot Motion(imitate)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11065   Accepted: 5378 Des ...

  6. A. Robot Sequence

    A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  8. pybot/robot命令参数说明

    Robot Framework -- A generic test automation framework Version: 3.0 (Python 3.4.0 on win32) Usage: r ...

  9. ACM题目————Robot Motion

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

随机推荐

  1. 递归与尾递归(C语言)

    原文:递归与尾递归(C语言)[转] 作者:archimedes 出处:http://www.cnblogs.com/archimedes/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留 ...

  2. Oracle SqlPlus 方向键的方法和解决的退格键失效

    SqlPlus中退格键和方向键的设置 在刚装好的Oracle中,我们使用SqlPlus会发现很的蹩脚,不仅退格键不好用,方向键也不行调出history.以下有几种解决方法. 1.能够使用ctrl+Ba ...

  3. WEB开发中常用的正则表达式集合

    在计算机科学中,正则表达式用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串.在WEB开发中,正则表达式通常用来检测.查找替换某些符合规则的字符串,如检测用户输入E-mai格式是否正确,采集符 ...

  4. OCP-1Z0-051-题目解析-第11题

    11. View the Exhibit and examine the structure of the PRODUCTS table.All products have a list price. ...

  5. GIMP也疯狂之动态图的制作(一)

    写在前面的话:本系列gimp教程已首发在Linux吧(Go),之所以重新发表是因为便于博主分类并且可以重新整理,用作记录.本系列的侧重不是GIF的教程,而是gimp教程,想更好的制作GIF图片请使用专 ...

  6. Android正在使用Handler实现消息分发机制(两)

    在开始这篇文章之前,.首先,我们在总结前两篇文章Handler, Looper和MessageQueue像一些关键点: 0)在创建线程Handler之前,你必须调用Looper.prepare(), ...

  7. android application简要类(一)

    每次应用程序执行.应用application保持实例化的阶级地位.推而广之applicaiton类别,能够完成以下3长期工作: 1.至android应用级事件,如广播的实现中低声回应. 2.传递应用程 ...

  8. IQueryable与IQEnumberable的区别

    IEnumberable接口: 公开枚举器,该枚举器支持在指定类型的集合上进行简单迭代.也就是说:实现了此接口的object,就可以直接使用froeach遍历此object; IQueryable接口 ...

  9. RabbitMq install on Centos6.3

    安装服务(root) step 1:  启用EPEL:EPEL是一个Fedora Project 推出的 EPEL(Extra Packages for Enterprise Linux),EPEL是 ...

  10. Unit Of Work-工作单元

    Unit Of Work-工作单元 阅读目录: 概念中的理解 代码中的实现 后记 掀起了你的盖头来,让我看你的眼睛,你的眼睛明又亮呀,好像那水波一模样:掀起了你的盖头来,让我看你的脸儿,看看你的脸儿红 ...