[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 ( T100). 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 ...
随机推荐
- DNS使用的是TCP协议还是UDP协议
原文:http://benbenxiongyuan.iteye.com/blog/1088085 DNS同时占用UDP和TCP端口53是公认的,这种单个应用协议同时使用两种传输协议的情况在TCP/IP ...
- Web标准:九、CSS表单设计
Web标准:九.CSS表单设计 知识点: 1.改变文本框和文本域样式 2.用图片美化按钮 3.改变下拉列表样式 4.用label标签提升用户体验 1)改变文本框和文本域样式 文本框标签:<i ...
- ubuntu的文本界面修改字体大小
使用命令: dpkg-reconfigure console-setup
- 【c++】c++中重载输出操作符,为什么要返回引用
针对:ostream & operator <<(ostream & os, const ClassType &object) 说明几点: 1.第一个形参为对ost ...
- linux下静默安装 weblogic12.2.1.3中间件
第一步:准备需要的安装包文件,这里注意 weblogic12.2.*需要的最低JDK版本为1.8以上 1.查看当前的镜像列表:docker images 2.运行镜像,并进入容器,这里运行基本的cen ...
- centos6.6 下 安装 php7 按 nginx方式
1.安装必要的依赖库 > yum -y install gd zlib libjpeg libjpeg-devel libpng libpng-devel freetype freetype-d ...
- 纯净版Windows7系统迅雷下载路径
windows 7 旗舰版64位------------------- Windows 7 Ultimate (x64) - DVD (Chinese-Simplified) 详细信息 文件名 ...
- 面向对象设计模式纵横谈:Factory Method 工厂方法模式(笔记记录)
从耦合关系谈起 耦合关系直接决定着软件面对变化时的行为 -模块与模块之间的紧耦合使得软件面对变化时,相关模块都要随之更改 -模块与模块之间的松耦合使得软件面对变化时,一些模块更容易被替换或者更改,但其 ...
- POJ 2585.Window Pains 拓扑排序
Window Pains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1888 Accepted: 944 Descr ...
- Windows系统文件mshtml.dll
今天,在vista 32bit,sp 2,IE7的机器上跑开发的软件产品,打开IE,被测系统总是崩溃,换了一台机器,同样的配置环境,却没有重现. 同事的分析很详细,学习了 I tried this c ...