《.NET程序员面试宝典》10.7

上传人:woxinch****an2018 文档编号:37447284 上传时间:2018-04-16 格式:DOC 页数:6 大小:62.50KB
返回 下载 相关 举报
《.NET程序员面试宝典》10.7_第1页
第1页 / 共6页
《.NET程序员面试宝典》10.7_第2页
第2页 / 共6页
《.NET程序员面试宝典》10.7_第3页
第3页 / 共6页
《.NET程序员面试宝典》10.7_第4页
第4页 / 共6页
《.NET程序员面试宝典》10.7_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《《.NET程序员面试宝典》10.7》由会员分享,可在线阅读,更多相关《《.NET程序员面试宝典》10.7(6页珍藏版)》请在金锄头文库上搜索。

1、10.7 其他面面试试例例题题 1: :MARS ROVERS 问题。美国著名软件公司 T 面试题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 Ea

2、rth. A rovers 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 le

3、ft 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 he

4、ading. Assume that the square directly North from (x, y) is (x, y+1).INPUTThe 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

5、 lines of input. The first line gives the rovers 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 rovers orientation. Eac

6、h rover will be finished sequentially, which means that the second rover wont start to move until the first one has finished moving.100. NET 程序员面试宝典宝典OUTPUTThe output for each rover should be its final co-ordinates and heading.INPUT AND OUTPUTTest Input: 5 5 1 2 N LMLMLMLMM 3 3 E MMRMMRMRRM Test Out

7、put: 1 3 N 5 1 E 火星探测器问题。 一小队机器人探测器将由 NASA 送上火星高原,探测器将在这个奇 特的矩形高原上行驶。用它们携带的照相机将周围的全景地势图发回地球。每个探测器的方向和位置将由一个(x, y)系坐标图和一个表示地理 方向的字母表示出来。为了方便导航,平原将被划分为网格状。位置坐标 示例:0,0,N,表示探测器在坐标图的左下角,且面朝北方。为控制探测 器,NASA 会传送一串简单的字母。可能传送的字母为:“L”、 “R”和“M”。 “L”和“R”分别表示使探测器向左、向右旋转 90o,但不离开它所在地点。 “M”表示向前开进一个网格的距离,且保持方向不变。假设以

8、广场(高原) 的正北方向为 Y 轴的指向。 输入:首先输入的 line 是坐标图的右上方。假定左下方顶点的坐标为 (0, 0)。剩下的要输入的是被分布好的探测器的信息。每个探测器需要输入 两个 lines。第一条 line 提供探测器的位置,第二条是关于这个探测器怎样 进行高原探测的一系列说明。位置是由两个整数和一个区分方向的字母组 成的,对应了探测器的(x, y)坐标和方向。每个探测器的移动将按序完成, 即后一个探测器不能在前一个探测器完成移动之前开始移动。 输出:每个探测器的输出应该是它行进到的最终位置坐标和方向。 输入和输出测试如下。 期待的输入:5 5101第 10 章 继承与接口1

9、2 N LMLMLMLMM 3 3 E MMRMMRMRRM 期待的输出:1 3 N 5 1 E 答案:答案: 程序完整代码如下。using System; using System.Collections;namespace ConsoleApplication5 enum Heading E,S,W,N; enum X_way E = 1,S = 0,W = -1,N = 0; enum Y_way E = 0,S = -1,W = 0,N = 1;class Area private static int area_X; private static int area_Y; privat

10、e static ArrayList aryRovers = new ArrayList(); public Area() protected void AddRover(Rover aRover) aryRovers.Add(aRover); public static bool SetArea(int x, int y) if(area_X = 0 area_Y = y; return true; else return false; public static string GetState() string strTemp = “; foreach(Rover aobj in aryR

11、overs) strTemp += String.Format(“0 1 2 “,aobj.X,aobj.Y,aobj.heading); return strTemp; public static bool CheckArea(int x,int y) if(x = 0 try stringcTemp=strTemp.Trim().Split(new char); Area.SetArea(Convert.ToInt32 (cTemp0),Convert.ToInt32(cTemp1); catch Console.WriteLine(“Error.“); while(strTemp = C

12、onsole.ReadLine().ToUpper() != “State“.ToUpper() try string cTemp = strTemp.Trim().ToUpper(). Split(new char ); Rover aRover = new Rover(Convert.ToInt32 (cTemp0),Convert.ToInt32(cTemp1), (Heading)Enum.Parse(typeof(Heading), cTemp2); strTemp = Console.ReadLine().ToUpper(); foreach(char active in strTemp. ToCharArray() switch(active) case L: aRover.Turnning(true); break; case R: aRover.Turnning(false); break; case M: aRover.Move(); break; catch(Exception ex) Console.WriteLine(“Error.“); Console.WriteLine(Area.GetState();104. NET 程序员面试宝典宝典Console.Read();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 高中教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号