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的更多相关文章

  1. 12503 - Robot Instructions

      Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given som ...

  2. [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]

      Robot Instructions  You have a robot standing on the origin of x axis. The robot will be given som ...

  3. poj1573 Robot Motion

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12507   Accepted: 6070 Des ...

  4. 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 ...

  5. Robot Motion(imitate)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11065   Accepted: 5378 Des ...

  6. A. Robot Sequence

    A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. POJ 1573 Robot Motion(BFS)

    Robot Motion Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12856   Accepted: 6240 Des ...

  8. pybot/robot命令参数说明

    Robot Framework -- A generic test automation framework Version: 3.0 (Python 3.4.0 on win32) Usage: r ...

  9. ACM题目————Robot Motion

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

随机推荐

  1. delphi TeeChart保存3种图片文件

    var vForm: Tfrm_ChemaShowMainChild;begin vForm := GetActiveForm; vForm.cht_Edit.SaveToMetafile('C:\1 ...

  2. nmon基础

    nmon是分析 AIX 和 Linux 性能的免费工具 最简单的安装方式(Ubuntu apt源) sudo apt-get install nmon 在terminal下打开nmon 敲CMD,出现 ...

  3. 基于opencv的手写数字识别(MFC,HOG,SVM)

    参考了秋风细雨的文章:http://blog.csdn.net/candyforever/article/details/8564746 花了点时间编写出了程序,先看看效果吧. 识别效果大概都能正确. ...

  4. STM32 UART 重映射

    在进行原理图设计的时候发现管脚的分配之间有冲突,需要对管脚进行重映射,在手册中了解到STM32 上有很多I/O口,也有很多的内置外设像:I2C,ADC,ISP,USART等 ,为了节省引出管脚,这些内 ...

  5. 精品手游《里奥的财富》高清版逆向移植家用机与PC平台(转)

    冒险动作游戏<里奥的财富>于去年10月登陆移动平台,曾荣获App Store“年度优秀游戏”.开发商宣布将推出其HD版本,近期会陆续登陆PS4.PC.MAC.Xbox One平台. 由瑞典 ...

  6. 【LeetCode】70 - Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  7. 面试体验:Facebook 篇(转)

    http://www.cnblogs.com/cathsfz/archive/2012/11/05/facebook-interview-experience.html 2012-11-05 08:2 ...

  8. To follow the path

    look to the master,    follow the master,    walk with the master,    see through the master,    bec ...

  9. 基于gSOAP使用头文件的C语言版web service开发过程例子

    基于gSOAP使用头文件的C语言版web service开发过程例子 一服务端 1 打开VS2005,创建一个工程,命名为calcServer. 2 添加一个头文件calc.h,编辑内容如下: 1// ...

  10. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误

    原因1:给定目录下jvm.dll不存在. 对策:(1)重新安装jre或者jdk并配置好环境变量.(2)copy一个jvm.dll放在该目录下. 原因2:eclipse的版本与jre或者jdk版本不一致 ...