Robot Instructions
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3947
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
(
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
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int now; char inst[110][7];
int b[110]; void s(int i)
{
switch(inst[i][0])
{
case 'L':
now--;break;
case 'R':
now++;break;
case 'S':
s(b[i]);break;
}
} int main()
{
int t,n,i;
char x[5];
scanf("%d",&t);
while(t--)
{
memset(b,0,sizeof(b));
now = 0;
scanf("%d",&n);
for(i = 1; i <= n; i++)
{
scanf("%s",&inst[i]);
if(inst[i][0] == 'S')
{
scanf("%s",&x);
scanf("%d",&b[i]);
}
s(i);
}
printf("%d\n",now);
} return 0;
}
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 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]
Robot Instructions You have a robot standing on the origin of x axis. The robot will be given som ...
- 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 ...
随机推荐
- dll 打包
开发程序的时候经常会引用一些第三方的DLL,然后编译生成的exe文件就不能脱离这些DLL独立运行了. 但是,很多时候我们本想开发一款只需要一个exe就能完美运行的小工具.那该怎么办呢? 下文介绍一种超 ...
- Python 学习笔记(五)杂项
1. Assert assert len(unique_characters) <= 10, 'Too many letters' #…等价于: if len(unique_characters ...
- Delphi下使用OpenOffice+JodConverter+SWFtools进行文件转换
目的:office文件转换为PDF或SWF,最终可使用Flexpaper调用adobe flash player进行浏览 放弃两个文件转换工具: 1.FlashPaper,转换出的文件由于自带工具栏, ...
- Flex3.0 Loader类的练习
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="h ...
- 桶排序-C-结构体排序
struct TS { int index; ]; }; ] = {{,,,,,"s8"}}; ]; int i; int length = sizeof(a) / sizeof ...
- php 扩展apc 参数优化
编辑php.ini 输入下面 [apc] apc.enabled=1apc.shm_segments = 1apc.shm_size = 1Gapc.ttl = 0apc.user_ttl = 0ap ...
- Northwind数据库表字段介绍
① Categories:种类表 相应字段: CategoryID :类型ID: CategoryName:类型名; Description:类型说明; Picture:产品样本 ② Customer ...
- LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)
http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS Memory L ...
- JavaScript学习——内置属性
在js中,几乎所有的对象都是同源对象,都继承Object对象.对象的内置属性指的是它们作为Object实例所具有的属性,这些属性通常反映对象本身的基本信息和数据无关.因此我们称它们为元属性.这些属性通 ...
- tryparse的用法,^0*[1-9]\d*$
Entry entry = new Entry(); Int32 iParam; if(Int32.TryParse(entry.ajh,out iParam)) { /*如果转换成功就输出iPara ...