12503 - Robot Instructions
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的更多相关文章
- [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]
Robot Instructions You have a robot standing on the origin of x axis. The robot will be given som ...
- Robot Instructions
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- poj1573 Robot Motion
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12507 Accepted: 6070 Des ...
- 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 ...
- Robot Motion(imitate)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11065 Accepted: 5378 Des ...
- A. Robot Sequence
A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- POJ 1573 Robot Motion(BFS)
Robot Motion Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12856 Accepted: 6240 Des ...
- pybot/robot命令参数说明
Robot Framework -- A generic test automation framework Version: 3.0 (Python 3.4.0 on win32) Usage: r ...
- ACM题目————Robot Motion
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
随机推荐
- 浅谈JavaScript性能
最近在JavaScript性能方面有所感悟,把我的经验分给大家: 说到JavaScript,就不得不说它的代码的运行速度—— 在我初学JavaScript的时候,只是觉得它是一个很强大的脚本.渐渐的, ...
- 轻量级IOC框架Guice
java轻量级IOC框架Guice Guice是由Google大牛Bob lee开发的一款绝对轻量级的java IoC容器.其优势在于: 速度快,号称比spring快100倍. 无外部配置(如需要使用 ...
- selenium2入门 用selenium安装、加载、启用插件(一)
一:下载 下载地址是:http://docs.seleniumhq.org/download/
- 1.2 如何使用LINQ
LINQ作为一种数据查询编码方式,它本身不是独立的开发语言,也不能进行应用程序开发.但是在.NET 4.5中,可以在C#中集成LINQ查询代码. 在任何源代码文件中,要使用LINQ查询功能,必须引用S ...
- Android中常用的颜色
代码: <?xml version=”″ ?> <resources> <color name=”white”>#ffffff</color><! ...
- 自己动手实现Expression翻译器 – Part Ⅲ
上一节实现了对TableExpression的解析,通过反射创建实例以及构建该实例的成员访问表达式生成了一个TableExpression,并将其遍历格式化为”Select * From TableN ...
- Visual Studio 当前不会命中断点的问题
这个问题一般有两个版本 1.当前不会命中断点,还没有为该文档加载任何符号. 2.当前不会命中断点,源代码与原始版本不同. 要解决第一个问题,就要了解一种文件格式“PDB(Program DataBas ...
- Javascript多线程引擎(五)
Javascript多线程引擎(五)之异常处理 C语言没有提供一个像Java一样的异常处理机制, 这就带来了一个问题, 对于一个子函数中发生异常后, 需要在父函数调用子函数的位置进行Check, 如果 ...
- 【推荐分享】Python电子书,视频教程(Let's Python系列视频教程等)(百度网盘)
资源都放在百度网盘里了. Python视频教程(Python Django视频教程全集—台湾辅仁大学):http://pan.baidu.com/s/1dDgiWIt Python视频教程(let's ...
- IIS7.5下的httpModules设置
部署到IIS7.5上httpModule不起作用了,原来是iis7里面的网站应用程序池使用了默认的“集成模式”,所以所有的http请求处理都托管给了 IIS,web.config里面的配置就不起效了. ...