[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 ...
随机推荐
- Css定位元素
Css定位selenium极力推荐使用Css定位,而不是xpath定位元素,原因是css定位比xpath定位块,速度快,语法更加简洁 css常用的定位方法:1.find_element_by_css_ ...
- 修改mysql数据库 允许远程访问
首先使用root身份进入MySQL mysql>use mysql; //进入mysql表 mysql> selecthost,user from user; //查看结果是不是root ...
- js 递归调用
js递归调用 function fact(num) { ) { ; } else { ); } } 以下代码可导致出错: var anotherFact = fact; fact = null; al ...
- windows常用运行命令总结
开始→运行→命令集锦 winver---------检查Windows版本 wmimgmt.msc----打开windows管理体系结构(WMI) wupdmgr--------windows更新程序 ...
- hreeJS加载Obj资源后如何实现内存释放?
问题: 我利用ThreeJS做了一个在同一个场景下动态加载Obj的页面,具体功能是:点击按钮A:加载A模型,点击按钮B:加载B模型...现在的问题是,前面已经加载过的模型,无法实现释放,内存一直在累加 ...
- jquery正则表达式验证:验证身份证号码
需求说明: 前端页面使用正则表达式验证文本输入框输入的身份证号码是否符合规则. 代码说明: 这里只介绍正则表达式部分,其他部分的代码不做介绍.如有其它需求请自行修改即可. 步骤一:建立一个页面可以是h ...
- MySql中4种批量更新的方法
最近在完成MySql项目集成的情况下,需要增加批量更新的功能,根据网上的资料整理了一下,很好用,都测试过,可以直接使用. mysql 批量更新共有以下四种办法 1..replace into 批量更新 ...
- Ruby环境配置
一.rvm 1.简介 rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换. 2.安装步骤 1.新建文件:rvm-installer.sh vi rvm-installer.sh ...
- illumina SBS测序详解
illumina SBS测序详解 2018年01月02日 09:33:56 sixu_9days 阅读数:9789 标签: 生物信息学二代测序 更多 个人分类: 测序原理 最近回头重新看了illl ...
- BZOJ 1345[BOI]序列问题 - 贪心 + 单调栈
题解 真的没有想到是单调栈啊. 回想起被单调栈支配的恐惧 最优情况一定是小的数去合并 尽量多的数,所以可以维护一个递减的单调栈. 如果加入的数比栈首小, 就直接推入栈. 如果加入的数大于等于栈首, 必 ...