Amazon online test)

Source: Internet
Author: User

亚马逊的在线笔试也是OJ题目,跟谷歌差不多。当然比较诧异的是,其实难度也跟谷歌差不多!

 

第一题:

巨麻烦的一道题目,大意是比较扑克牌序列,每个序列四张牌

 

规则一:

四张牌相同。自然数字大的胜出,比如3,3,3,3 < 6,6,6,6

规则二:

四张牌连续。当然序列最大的那个胜出。但是有个小trick,A在这里默认表最大牌,但是如果后接2,3,4,则A表最小牌,为了获得连续序列

比如A,2,3,4 < J,Q,K,A

规则三:

有三张相同。以每个序列相同牌较大的胜出。

比如3,3,3,2>2,2,2,A

规则四:

两个对子。当然以对子较大的胜出,最大的对子相同,则以次大的对子较大者胜出。

比如4,4,3,3 > 4,2,4,2

规则五:

一个对子。对子较大者胜出,如果对子相同,则比较剩下较大牌,如果还相同,比较次大牌

3,3,7,4 < 3,3,7,5

规则六:

如果以上皆不满足,则按照大牌>小牌比较(即从最大牌开始比较,分出高下为止)

 

如果两个序列不属于同一规则,则规则小者胜出。

如果序列一大于序列二,输出1,反之输出-1;如果序列相同,输出0。

如果发现作弊,即两副牌中某张牌数量超过5张,则输出-2。

 

OK,以上是题目描述。这个题目,个人感觉主要是读懂题意,实现起来确实也非常麻烦,但是没啥难点,但是也会搞很久。

主要是几点:

1、解析输入字符串(如果你用C、C++,会比较蛋疼)

2、适配规则逻辑(更像状态机)

3,比较逻辑

好像也没啥是吧,但是本屌丝做了N久才把Case全过。而且代码巨长,200+行,准备吃饭去了,代码稍后奉上。

二三题待续

亚马逊在线笔试(2014/10/9)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.