Fork me on GitHub
ThoughtWorks Merchant's Guide To The Galaxy

ThoughtWorks笔试题之Merchant's Guide To The Galaxy解析

一、背景

在某网站上看到ThoughtWorks在武汉招人,待遇在本地还算不错,就投递了简历。第二天HR就打开电话,基本了解了一下情况(工作环境不错,男人妹子比例:1:1,双休,六险一金,满一年年假15天,病假8天,月薪1W--2W)。然后立马收到一封:Coding Assignment的笔试题目。网上搜索了一下,发现这个公司还是挺大的,公司面试流程是出了名的繁杂和苛刻。据说有8轮:电话面试=》笔试=》Homework=》结对编程(中午管饭)=》技术面试=》PM面试=》HR Manager的面试=》Boss面谈。

了解到武汉这边的主要是做知道华为这样的公司做敏捷开发培训,需要出差,也会有自己公司的一些些代码的需求。这边公司规模也就20几个人。希望对其他想去的童鞋有所帮助。

管它呢,试试再说/本文重点说一下笔试题目,因为我觉得还挺有意思的。

 

不好意思,刚收到邮件通知,我己经阵亡,说是没有适合我 skills and background 的职位。莫非跟这个题目有关,大家帮我看一下哦。

二、题目:

三个问题任选其一:我就选了第一个”Problem One: Merchant's Guide To The Galaxy“,另外两道题有需要的原有找我要。

题干给大家贴出来,下面有中文说明,可跳过。

You decided to give up on earth after the latest financial collapse left 99.99% of the earth's population with 0.01% of the wealth. Luckily, with the scant sum of money that is left in your account, you are able to afford to rent a spaceship, leave earth, and fly all over the galaxy to sell common metals and dirt (which apparently is worth a lot).
 
Buying and selling over the galaxy requires you to convert numbers and units, and you decided to write a program to help you.
 
The numbers used for intergalactic transactions follows similar convention to the roman numerals and you have painstakingly collected the appropriate translation between them.
 
Roman numerals are based on seven symbols:

Symbol

Value

I

1

V

5

X

10

L

50

C

100

D

500

M

1,000

 
Numbers are formed by combining symbols together and adding the values. For example, MMVI is 1000 + 1000 + 5 + 1 = 2006. Generally, symbols are placed in order of value, starting with the largest values. When smaller values precede larger values, the smaller values are subtracted from the larger values, and the result is added to the total. For example MCMXLIV = 1000 + (1000 − 100) + (50 − 10) + (5 − 1) = 1944.
 
  • The symbols "I", "X", "C", and "M" can be repeated three times in succession, but no more. (They may appear four times if the third and fourth are separated by a smaller value, such as XXXIX.) "D", "L", and "V" can never be repeated.
  • "I" can be subtracted from "V" and "X" only. "X" can be subtracted from "L" and "C" only. "C" can be subtracted from "D" and "M" only. "V", "L", and "D" can never be subtracted.
  • Only one small-value symbol may be subtracted from any large-value symbol.
  • A number written in [16]Arabic numerals can be broken into digits. For example, 1903 is composed of 1, 9, 0, and 3. To write the Roman numeral, each of the non-zero digits should be treated separately. Inthe above example, 1,000 = M, 900 = CM, and 3 = III. Therefore, 1903 = MCMIII.
 
Input to your program consists of lines of text detailing your notes on the conversion between intergalactic units and roman numerals.
 
You are expected to handle invalid queries appropriately.
 
Test input:
glob is I
prok is V
pish is X
tegj is L
glob glob Silver is 34 Credits
glob prok Gold is 57800 Credits
pish pish Iron is 3910 Credits
how much is pish tegj glob glob ?
how many Credits is glob prok Silver ?
how many Credits is glob prok Gold ?
how many Credits is glob prok Iron ?
how much wood could a woodchuck chuck if a woodchuck could chuck wood ?
 
Test Output:
pish tegj glob glob is 42
glob prok Silver is 68 Credits
glob prok Gold is 57800 Credits
glob prok Iron is 782 Credits
I have no idea what you are talking about

 

可以用:Java, Ruby, or C#, JavaScript.

 

中文:大意就是我成了地球首富,然后有很多钱,但是地球已经不适合人类居住了,需要跑到银河系去做生意,但是银河系使用的是罗马字母表示钱,所以座位程序员的我打算自己写一个罗马字母和十进制数字互转的小程序,以帮助我做生意。

罗马字母有: I,V,X,L,C,D,M

转换规则

1. I:可以表示十进制数字1,V:可以表示十进制数字5,X:可以表示十进制数字10,L:可以表示十进制数字50,C:可以表示十进制数字100,D:可以表示十进制数字500,M:可以表示十进制数字1000;

2.I, X, C, and M可以重复出现最多3次;

3.一般是从后往前排列:即MDCLXVI的顺序,当然也允许相邻的两个倒序,但是需要符合以下规则:

   I :只能组合IV ,IX

   X:只能组合XL,XC

   C:只能组合CD,CM

   V,L,D不能倒序

 

大概是这个意思,上周做的,现在大脑还残存这些碎片。

 

三、我的思路

既然要考察面向对象的编程,就建一个Roman的类表示单个罗马字母,根据转换规则添加一些Property,如下:

 View Code

在新建一个类专门做转换:

 View Code

程序输出:

 

代码不解释,请大牛批评指正。

 代码下载:https://files.cnblogs.com/deepleo/RomanNumber.rar

posted on 2014-08-19 00:10  HackerVirus  阅读(2422)  评论(1编辑  收藏  举报