[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 ...
随机推荐
- 1D Blending
[1D Blending] BlendTree有类型之分,分为1D.2D.本文记录1D. 1D Blending blends the child motions according to a sin ...
- webpack 常用插件及作用
copy-webpack-plugin :复制文件到目标文件夹.在开发时使用热模替换,(没有生成dist 文件夹,都在内存中),如果想引用某一个js文件,直接写script标签是找不到的,因为服务器内 ...
- 慕课网access_token的获取(下)
接口调用返回的结果是两个字段:access_token和expires_in,所以需要创建一个实体类封装这两个字段 运行测试类WeixinTest.java控制台打印出错误信息 重置开发者密钥试试看 ...
- swift UICollectionView使用
方法1:创建 的时候注册 layout /// 时间view private lazy var timeCollectionV: UICollectionView = { 1.直接注册 并设置好 UI ...
- RedisUtil工具类
转载:http://blog.csdn.net/liuxiao723846/article/details/50401406 1.使用了jedis客户端,对redis进行了封装,包括: 1)使用了re ...
- Halcon开发环境和数据结构介绍——第1讲
1.Halcon是什么?如何初步了解Halcon? 这点我讲得不太好,不如给大家看看三个链接: ① Halcon官方网站:https://www.mvtec.com/products/halcon/ ...
- wm_concat函数
wm_concat函数 wm_concat函数 一般分类 — 作者 zzy020128 @ 12:21 首先让我们来看看这个神奇的函数wm_concat(列名),该函数可以把列值以",& ...
- 201621123008 《Java程序设计》第六周实验总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 2. 书面作业 1. clone方法 1.1 在 ...
- 纯css手写圆角气泡对话框 微信小程序和web都适用
嗯……我们设计师强烈要求一定要圆角!圆角的气泡对话框,不要那种尖角的.这其中还遇上了个尴尬的问题,z-index不生效 无非就是两种方法,一种是使用图片再定位拼接起来使用,太简单了具体就不详细的说了. ...
- 2018.09.30 bzoj2288:生日礼物(贪心+线段树)
传送门 线段树经典题目. 每次先找到最大子段和来更新答案,然后利用网络流反悔退流的思想把这个最大字段乘-1之后放回去. 代码: #include<bits/stdc++.h> #defin ...