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# TextBox实现全选

    A. 设置全局变量: 1.定义了个全局变量放本次点击的textbox的名字,默认为空. 2.textbox的Enter事件里SelectAll()一下 3.Click事件里判断全局变量是否是该text ...

  2. VMware7安装CentOS6.5教程

    VMware7安装CentOS6.5教程 http://www.91linux.com/html/2014/CentOS_0415/9727.html工欲善其事,必先利其器.学习linux系统,必须先 ...

  3. C#中文本模板(.tt)

    关于C#中文本模板(.tt)的简单应用 这两天做项目突遇 .tt文件,之前没有接触过,so查询学习做笔记,帮助记忆和后来者. 在项目添加中点击选择文本模板 下面贴出代码,做了简单的注释 1 2 3 4 ...

  4. 个推推送 产品SDK常见问题检查

    作者:Hong Jack链接:https://zhuanlan.zhihu.com/p/20733333来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 通知和消息有什么 ...

  5. Javascript多线程引擎(三)

    Javascript多线程引擎(三) 完成对ECMAScript-262 3rd规范的阅读后, 列出了如下的限制条件 1. 去除正则表达式( 语法识别先不编写) 2. 去除对Function Decl ...

  6. Visual Studio 2013发布Cloud Service至Azure China

    Visual Studio 2013发布Cloud Service至Azure China <Windows Azure Platform 系列文章目录> 之前有很多网友询问我如何通过VS ...

  7. FormsAuthentication登录ReturnUrl使用绝对路径

    ASP.NET]更简单的方法:FormsAuthentication登录ReturnUrl使用绝对路径   被这个问题困扰多年,今天终于找到了更简单的解决方法,分享一下. 问题场景 假设我们在i.cn ...

  8. rebbitmq-RPC(C#)

    RPC(Remote Procedure Call Protocol)——远程过程调用协议 运行时,一次客户机对服务器的RPC调用,其内部操作大致有如下十步: 1.调用客户端句柄:执行传送参数 2.调 ...

  9. nginx 重定向到index.php

    location /keywords {                index index.php;                try_files $uri $uri/ /keywords/i ...

  10. win32多线程-异步过程调用(asynchronous Procedure Calls, APCs)

    使用overlapped I/O并搭配event对象-----win32多线程-异步(asynchronous) I/O事例,会产生两个基础性问题. 第一个问题是,使用WaitForMultipleO ...