题目描述

A squad of robotic rovers are to be landed by NASA on a plateau on Mars.

This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control a rover, NASA sends a simple string of letters. The possible letters are 'L ', 'R ' and 'M '. 'L ' and 'R ' makes the rover spin 90 degrees left or right respectively, without moving from its current spot.

'M ' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

INPUT:

The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.

The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover 's position, and the second line is a series of instructions telling the rover how to explore the plateau.

The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover 's orientation.

Each rover will be finished sequentially, which means that the second rover won 't start to move until the first one has finished moving.

OUTPUT

The output for each rover should be its final co-ordinates and heading.

INPUT AND OUTPUT

Test Input:

5 5

1 2 N

LMLMLMLMM

3 3 E

MMRMMRMRRM

强势中文翻译

火星探测器

一小队机器人探测器将由NASA送上火星高原,探测器将在这个奇特的矩形高原上行驶。

用 它们携带的照相机将周围的全景地势图发回到地球。每个探测器的方向和位置将由一个x,y系坐标图和一个表示地理方向的字母表示出来。为了方便导航,平原将 被划分为网格状。位置坐标示例:0,0,N,表示探测器在坐标图的左下角,且面朝北方。为控制探测器,NASA会传送一串简单的字母。可能传送的字母为: 'L ', 'R '和 'M '。 'L ',和 'R '分别表示使探测器向左、向右旋转90度,但不离开他所在地点。 'M ' 表示向前开进一个网格的距离,且保持方向不变。假设以广场(高原)的直北方向为y轴的指向。

输 入:首先输入的line是坐标图的右上方,假定左下方顶点的坐标为0,0。剩下的要输入的是被分布好的探测器的信息。每个探测器需要输入wo lines。第一条line 提供探测器的位置,第二条是关于这个探测器怎样进行高原探测的一系列说明。位置是由两个整数和一个区分方向的字母组成,对应了探测器的(x,y)坐标和方 向。每个探测器的移动将按序完成,即后一个探测器不能在前一个探测器完成移动之前开始移动。

输出:每个探测器的输出应该为它行进到的最终位置坐标和方向。输入和输出 测试如下:

期待的输入:

5 5

1 2 N

LMLMLMLMM

3 3 E

MMRMMRMRRM 期待的输出

1 3 N

5 1 E

题目分析:

这个题其实是thoughtworks里面员工用于娱乐的一道题,漏洞很多,比如出了矩阵的范围怎么办,两个探测器相遇该怎么办之类的问题,这道题都没有给出具体的方案,所以漏洞很多,纯属娱乐,代码以及解决方案如下

 #include<iostream>
#include<string> using namespace std;
enum dir {N=,E,S,W};//像友加1向左加3然后整体模上4,就可以实现一圈圈无间断的方向连续不断的变化
class mas
{
private:
int loc_line;
int loc_row;
char direction;
int number;
string duty;
public:
mas(int pos1, int pos2, char dir, string input)
:loc_line(pos1), loc_row(pos2), direction(dir), duty(input){}
~mas(){}
void change()
{
if (direction == 'N')
number = N;
else
if (direction == 'E')
number = E;
else
if (direction == 'S')
number = S;
else
if (direction == 'W')
number = W;
}
void rechange()//这里也可以用switch语句来实现,上面change函数也是一样的;方法不固定
{
if (number == N)
direction = 'N';
else
if (number == W)
direction = 'E';
else
if (number == S)
direction = 'S';
else
if (number == W)
direction = 'W';
}
void move(){
change();
int max = duty.size();
for (int i = ; i < max; i++)
{
switch (duty[i])
{
case 'L':number = (number + ) % ; break;
case 'R':number = (number + ) % ; break;
case 'M':
switch (number){
case :loc_row++; break;
case :loc_line++; break;
case :loc_row--; break;
case :loc_line--; break;
}
default:break;
}
}
rechange();
show();
}
void show(){ cout << loc_line << ' ' << loc_row << ' ' << direction << endl; }
}; int main()
{
int line, row;
int pos_line, pos_row;
char dir;
string input;
cin >> line >> row;
while (cin >> pos_line >> pos_row >> dir)
{
cin >> input;
mas rover(pos_line, pos_row, dir, input);
rover.move();
}
return ;
} 测试结果:

如有问题或错误或者你想说点什么请留言;

thoughtworks面试题分析与解答的更多相关文章

  1. Java陷阱一箩筐----面试题集及解答

    Java陷阱一箩筐----面试题集及解答 面试是没什么道理可讲的,它的题目有的不合情理.脱离实际.有在纸上写的,有当面考你的,也有在电话里问的,给你IDE的估计很少. 当然这些都是Java的基本题,那 ...

  2. 使用java理解程序逻辑 试题分析

      1.编译Java Applet源程序文件产生的字节码文件的扩展名为() A:.java B..class C:Html D:Exe 正确答案:B 试题分析: 本题考查的是Java程序的开发过程.J ...

  3. tomcat启动startup.bat一闪而过(分析与解答)

    tomcat启动startup.bat一闪而过(分析与解答) 方法/步骤     在正确配置Tomcat环境变量后,遇到很多次运行startup.bat后,一个窗口一闪而过的.为了分析导致tomcat ...

  4. Android面试题收录及解答10月刊

    前言 嗨,大家好,好久不见.这里跟大家侃侃这中间发生了什么. 一个月前呢,想准备面试,就网上随便找找面试题什么的,发现要么就是卖课的,要么就是不给详细回答的或者回答不够深的(也许是我没找到).反正稍微 ...

  5. 从一道面试题分析javascript闭包

    据说是一不注意就会做错的五道javascript面试题之一,我们来看看这道题长什么样 function Container( properties ) { var objthis = this; fo ...

  6. java android面试题分析总结

    本文参考多处,一并感谢! http://www.blogjava.net/fanyingjie/archive/2007/06/27/126467.aspx http://baike.baidu.co ...

  7. MySQL高级知识(七)——索引面试题分析

    前言:该篇随笔通过一些案例,对索引相关的面试题进行分析. 0.准备 #1.创建test表(测试表). drop table if exists test; create table test( id ...

  8. 某大型企业ospf面试题分析(含路由策略和路由过滤,及双点双向重发布)

    面试问题背景 本面试题来自国内最大通信技术公司之一,央企,有很多金融网项目. 了解行业的同学,一定知道事哪个企业. 上面试问题(取自百哥收集整理的面试总结大全,关注百哥CSDN或知乎,不定期分享名企面 ...

  9. 八皇后问题详细分析与解答(递归法解答,c#语言描述)

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题.该问题是十九世纪著名的数学家高斯1850年提出:在8X8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或 ...

随机推荐

  1. PowerDesigner 简单应用(转载)

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...

  2. 验证SQLServer死锁进程

    SELECT '现在没有阻塞和死锁信息' AS message -- 循环开始WHILE @intCounter <= @intCountProperties BEGIN-- 取第一条记录 SE ...

  3. Egret学习笔记 (Egret打飞机-9.子弹对敌机和主角的碰撞)

    运行起来,虽然主角飞机和敌机都在互相发射子弹,但是子弹打中了就和没打中效果是一样的.. 这一章我们就来处理子弹和飞机的碰撞问题. 我们所有的操作都是基于Main这个容器来做的.所以我就把这个处理放到M ...

  4. 一、Python介绍

    Python 是一门什么样的语言? python是一门动态解释性的强类型定义语言. 编程语言主要从以下几个角度为进行分类,编译型和解释型.静态语言和动态语言.强类型定义语言和弱类型定义语言,每个分类代 ...

  5. 在SpringBoot中配置aop

    前言 aop作为spring的一个强大的功能经常被使用,aop的应用场景有很多,但是实际的应用还是需要根据实际的业务来进行实现.这里就以打印日志作为例子,在SpringBoot中配置aop 已经加入我 ...

  6. Linux的内核和权限

    1.内核包括的子系统是 : 进程管理系统 . 内存管理系统 . I/O管理系统 和文件管理系统  等四个子系统. 2.Linux系统中某个可执行文件属于root并且有setid,当一个普通用户 mik ...

  7. hadoop/storm以及hive/hbase/pig区别整理

    STORM与HADOOP的比较 对于一堆时刻在增长的数据,如果要统计,可以采取什么方法呢? 等数据增长到一定程度的时候,跑一个统计程序进行统计.适用于实时性要求不高的场景.如将数据导到HDFS,再运行 ...

  8. ubuntu下动态链接库的编译和使用实例

    以下实例的环境是amd64 + ubuntu10.10 + g++ 4.4.5测试成功,在其他配置的机器上可能有一点区别.     动态库的使用方式中有两种,第一种是类似于静态库的使用,另一种我称之为 ...

  9. Ubuntu 11.04 NFS 配置

    安装 NFS 相关组件 sudo apt-get install nfs-kernel-server 增加 NFS 目录 sudo gedit /etc/exports #在文件中添加如下内容 /va ...

  10. DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别

    DriverStudio /***************************************************************************** * 功能: 通过 ...