ThoughtWorks 百年不变的面试题之 --- Merchant's Guide To The Galaxy

ThoughtWorks 百年不变的面试题之 --- Merchant's Guide To The Galaxy

Code: https://github.com/zifeiniu/Merchants-Guide-To-The-Galaxy

我选的第三道,罗马数字转换。。

题是做完了,也算对了。但是你就别抄了,因为没过。。 挂的原因之一是没有写ReadMe,所以我现在多写点ReadMe. 还有因为有面向过程的思想,没有使用最新语法(这也算被拒的理由)。

今年不适合跳槽啊,先去葡萄城面试,前三关都过了,最后一关(传说中面试思想)三个boss围着小圆桌,问:你要是和上司吵架了怎么办?然后我就被拒了。

有意思的是面试前三关出的算法题,我都答出来了,但是答案和他们想的不一样。然后他们就说其实还可以这样XXXXXX,最后我发现他们给的答案逻辑都有问题,被我指出了,当然是没办法拒了。

想起来挺悲剧,我也是一个五十多人的软件公司的技术总监,居然连ThoughtWorks机试题都没过。

-----------------------

最近朋友又去面试,我拿出来Push到Github上练练手。 大概讲一下,两个系统,一个问答系统 Analysis ,就是根据用户输入回答的。还有一个罗马数字转换系统RomanSystem,用户转换的。 记得要写ReadMe。 记得要写ReadMe。 记得要写ReadMe。

题目:

Description

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.

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 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. In the 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.

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 ?

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

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=36vhfka3k3cwg

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏HansBug's Lab

3361: [Usaco2004 Jan]培根距离

3361: [Usaco2004 Jan]培根距离 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 16  S...

3555
来自专栏高性能服务器开发

携程面试题

冬天,西风凛冽,天空阴沉,行人都急匆匆的奔走,到了家,烤着炉子,外边洋洋洒洒的下起了雪。知道什么是“晚来天欲雪”,什么是“红泥小火炉”。

3273
来自专栏码农阿宇

NopCommerce开源项目中很基础但是很实用的C# Helper方法

3963
来自专栏lonelydawn的前端猿区

Node.js力破江苏网警刑侦科推理试题

月前,江苏网警 在微博发布了一套《2018年刑侦科目推理试题》,可谓难倒了诸多英雄好汉,评论区内更是一片皮皮之音。 @二向箔icon: 高考前班主任教过我们,...

3257
来自专栏Guangdong Qi

iOS 简单易懂的粒子效果

2323
来自专栏Java帮帮-微信公众号-技术文章全总结

【学习经验】Java中常用英文

【学习经验】Java中常用英文 第一章: public['pʌblik] 公共的,公用的 static['stætik] 静的;静态的...

36410
来自专栏Python攻城狮

Python之禅

在Python交互式解释器中输 入import this就会显示Tim Peters的The Zen of python

941
来自专栏PPV课数据科学社区

趣文 | 程序员们,都进来看看编程语言之父都有谁

1、PHP PHP之父,Rasmus Lerdorf,1994年,为了要维护个人网页而制作的一个简单的用Perl语言编写的程序。这些工具程序用来显示 Rasmu...

3507
来自专栏小樱的经验随笔

BZOJ 1061: [Noi2008]志愿者招募【单纯形裸题】

1061: [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MB Submit: 4813  Solv...

3525
来自专栏数据结构与算法

P1828 香甜的黄油 Sweet Butter

题目描述 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖。把糖放在一片牧场上,他知道N(1<=N<=500)只奶牛会过来舔它,这样就能做出能卖好价钱的超甜...

2997

扫码关注云+社区

领取腾讯云代金券