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,如下:

 

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

程序输出:

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

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

ThoughtWorks Merchant's Guide To The Galaxy的更多相关文章

  1. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

  2. acpi和btrfs-安装opensuse时的选项

    g-------------------- 关于GPL和LGPL和QPL等 读书笔记:采用LGPL的代码,一般情况下它本身就是一个第三方库(别忘了LGPL最早的名字就是Library GPL),这时候 ...

  3. What is machine learning?

    What is machine learning? One area of technology that is helping improve the services that we use on ...

  4. 解密TTY

    本文内容来自The TTY demystified ,讲述了*NIX系统中TTY的历史与工作原理,看完后解决了我很多疑惑,于是做此翻译,与大家分享. 译者:李秋豪 江家伟 审校: V1.0 Sun M ...

  5. jquery mobiscroll 滑动、滚动

    mobiscroll : 滑动选择 2.13.2版本免费,官网(mobiscroll.com)收费 先从官方下载2.13.2体验版下来,查看例子结合官方API学习( http://docs.mobis ...

  6. Github上的1000多本免费电子书重磅来袭!

    Github上的1000多本免费电子书重磅来袭!   以前 StackOverFlow 也给出了一个免费电子书列表,现在在Github上可以看到时刻保持更新的列表了. 瞥一眼下面的书籍分类目录,你就能 ...

  7. Github 的一个免费编程书籍列表

    Index Ada Agda Alef Android APL Arduino ASP.NET MVC Assembly Language Non-X86 AutoHotkey Autotools A ...

  8. The TTY demystified

    http://www.linusakesson.net/programming/tty/index.php The TTY demystified Real teletypes in the 1940 ...

  9. Deep Dive into Neo4j 3.5 Full Text Search

    In this blog we will go over the Full Text Search capabilities available in the latest major release ...

随机推荐

  1. react.js 从零开始(一)

    React 是什么? 网络上的解释很多...我这里把他定义为 通过javascript 的形式组件化 html的框架... React 仅仅是 VIEW 层. React 提供了模板语法以及一些函数钩 ...

  2. 公交部署wifi热点,是否有必要?

    小城市.大城市,公交车永远匆匆路过的风景,他带我们到四方.马上.一些公交车也已覆盖免费wifi,只有在我看来,,路上wifi似乎没有太大用处.何出此言? 相比而言.在长途车.飞机.火车上构建wifi热 ...

  3. easyUI的combobox实现级联

    先简介下combobox: easyUI重写了select,取而代之的是combobox,有例如以下几种方式能够创建一个combobox 1.使用select标签,并加上class="eas ...

  4. UNIX环保进程

    学习的过程之前,先来了解下过程中的操作环境. main功能 过程总是开始main功能开始执行,我们编程,程序从main功能进行,它是原型例如,下面的: int main(int argc, char ...

  5. Matlab曲面拟合和插值

    插值和拟合都是数据优化的一种方法,当实验数据不够多时常常须要用到这样的方法来绘图. 在matlab中都有特定的函数来完毕这些功能. 这两种方法的确别在于: 当測量值是准确的,没有误差时,一般用插值: ...

  6. linux_安装_安装编译phantomjs 2.0的方法_转

    项目中要对数据公式webkit渲染,phantmjs 2.0的效果好比1.9好不少. 安装过程中 坑比较多. 转载文章: phantomjs 2.0最新版的官方不提供编译好的文件下载,只能自己编译,有 ...

  7. myql_链接丢失异常_mybaits _等框架_报错_The last packet successfully

    mysql 8小时问题的解决方法 转发: 别看是英文 ,写的很好 ,才转 Use Hibernate + MYSQL database development, link timeout proble ...

  8. hive union all 使用

    功能:将两个表中的 同样的字段拼接到一起 測试: create external table IF NOT EXISTS temp_uniontest_ta ( a1 string, a2 strin ...

  9. 【百度地图API】如何制作班级地理通讯录?LBS通讯录

    原文:[百度地图API]如何制作班级地理通讯录?LBS通讯录 摘要:班级通讯录必备的功能,比如人员列表,人员地理位置标注,展示复杂信息窗口,公交和驾车等.一般班级人员都不会超过300个,因为可以高效地 ...

  10. LeetCode——Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...