[ACM_模拟] UVA 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 that i is a positive integer not greater than the number of instructions before this.
Input
The first line contains the number of test cases T ( T
100). Each test case begins with an integer n ( 1
n
100), 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 题目大意:机器人在原点,有3种命令:LEFT坐标减1,RIGHT坐标加1,SAME AS n和第n个命令一样,问最后机器人的坐标。水题不解释!
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<cstring>
#include<sstream>
using namespace std;
int main(){
string str;
int T;cin>>T;
getline(cin,str);
while(T--){
int n;cin>>n;
getline(cin,str);
int move[];
int sum=;
for(int i=;i<=n;i++){
getline(cin,str);
if(str[]=='L')move[i]=-;
else if(str[]=='R')move[i]=;
else{
string temp=str.substr();
istringstream in(temp);
int t;
in>>t;
move[i]=move[t];
}
sum+=move[i];
}
cout<<sum<<'\n';
}return ;
}
[ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]的更多相关文章
- 12503 - Robot Instructions
Robot Instructions You have a robot standing on the origin of x axis. The robot will be given som ...
- [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]
"One thing is for certain: there is no stopping them;the ants will soon be here. And I, for one ...
- [ACM_模拟] UVA 12504 Updating a Dictionary [字符串处理 字典增加、减少、改变问题]
Updating a Dictionary In this problem, a dictionary is collection of key-value pairs, where keys ...
- Robot Instructions
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 微信小程序连接低功率蓝牙控制单片机上硬件设备
1.软件部分介绍 微信小程序是一种新的应用,用户不需要下载应用只用通过扫二维码或者打开链接就能使用,使用完后不需要卸载,直接关闭就行了.微信在2017年初推出微信小程序开发环境.任何企业,媒体,个人都 ...
- 云中树莓派(3):通过 AWS IoT 控制树莓派上的 Led
云中树莓派(1):环境准备 云中树莓派(2):将传感器数据上传到AWS IoT 并利用Kibana进行展示 云中树莓派(3):通过 AWS IoT 控制树莓派上的Led 云中树莓派(4):利用声音传感 ...
- js可以控制文件上传的速度吗?
为了减轻服务器负载,对于上传和下载的情况,我们需要进行流量控制,一般的方法是服务端做限流举措,比如很多ftp服务器,但是我想是不是可以使用前端js做呢? 顺着这个想法,我查了下资料,目前来看结论是No ...
- CKEditor 自主控制图片上传
在ASP.NET中使用CKEditor编辑器,如果想控制图片上传,即把上传的图片路径名存到数据中,可以自定义一个上传功能 首先自定义CKEditor的配置文件 在config.js中添加以下代码,红色 ...
- Java 基础 程序流程控制 (上)
Java程序流程控制 (上) Java程序大体分为三种流程控制结构:顺序结构.分支结构.循环结构 顺序结构 程序由上到下的逐行执行,中间没有任何跳转和判断语句. 示例代码如下: public clas ...
随机推荐
- WebDriverException: Message: f.QueryInterface is not a function
WebDriverException: Message: f.QueryInterface is not a function 使用webdriver打开c.highpin.cn,结果报错,见下图: ...
- bug-ajax
ajax 的get 方法参数及url的长度有限制 问题:url的参数只有一个url?id=101001000000000000000001 参数过长,ajax会报错. 解决方法:1,把get换成pos ...
- 鼠标滑过图片添加边框图片无位移[xyytit]
实现下面的效果,鼠标滑过图片添加边框图片无位移——鼠标滑过,图片只是加了边框,不会晃动: 参考代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...
- C#6.0新特性:var s = $"{12}+{23}={12+23}"
为什么会出现$符号,c#6.0才出现的新特性 var s = string.Fromat("{0}+{1}={2}",12,23,12+23) 用起来必须输入string.From ...
- db2 批处理
db2在Windows下执行批处理,需要使用两个.bat文件 1)把以下命令保存为first_do.bat@echo off@@ECHO ------------------------------- ...
- KMP(2)
KMP 算法(2):其细微之处 2017 年 05 月 13 日 • 技术 系列文章目录 KMP 算法(1):如何理解 KMP KMP 算法(2):其细微之处 本篇来谈一谈 KMP 的一些细微之处,直 ...
- [BAT]远程执行或停止计划任务
执行 schtasks /run /tn "IPADForAdvisor_QA_APITest" /s SZPCWIN2K801 /u msdomain1\jzhang6 /p j ...
- 社交类APP原型模板分享——微信
微信是一款社交类的APP应用——聊天软件,支持多人群聊. 交互效果主要有滚动内容界面.选择组件触发按钮状态变化.点击下拉展开列表.点击弹出面板等交互操作. 本原型由国产原型工具-Mockplus制作完 ...
- android 弹出软键盘将底部视图顶起问题
今天要做一个搜索功能,搜索界面采用AutoCompleteTextView做搜索条,然后下面用listview来显示搜索结果,而我的主界面是在底 部用tab做了一个主界面导航,其中有一个搜索按钮,因为 ...
- 关于document.write(来自网络)
对象属性: document.title //设置文档标题等价于HTML的<title>标签document.bgColor / ...