Huawei Machine Question "3"

Source: Internet
Author: User

Topic:

Poker game Everyone should be more familiar with, a deck of cards composed of 54, including 3~a,2 each 4, Xiao Wang 1, King 1 Zhang. The board is small to large with the following characters and string representation (where the lowercase joker denotes Xiao Wang, capital Joker to represent the king):)
3 4 5 6 7 8 9 ten J Q K A 2 joker Joker
Enter two hands, between hands with "-" connection, each hand each card is separated by a space, "-" There are no spaces on both sides, such as: 4 4 4 4-joker Joker
Please compare the size of the hands, output a larger card, if there is no comparison relationship then output error

Basic rules:

(1) input each hand may be a child, a pair, a straight (5 consecutive), three, bombs (four) and one of the Kings, there is no other case, by the input to ensure that both hands are legal, shun son has been from small to large ranks;
(2) In addition to the bomb and the king can be compared with all cards, other types of cards can only be compared with the same type of existence (for example, pairs and pairs, three compared with three), regardless of the demolition of the situation (such as: Split the child into sub-)
(3) The size of the rules and common understanding of the usual rules of the same, sub, pair, three comparison of the board size; CIS compared to the smallest card size; The bomb is bigger than all the cards in front, the bombs compare the board size; The king is the biggest card;
(4) The input of the hands will not appear equal to the situation.

Answer hint:

(1) Apart from bombs and to kings, others must be compared to the same type.
(2) input has been guaranteed legitimacy, do not check whether the input is a legitimate card.
(3) The input straights have been sorted from small to large, so no more sorting is necessary.

Thinking Analysis:
    • According to test instructions 3 is the smallest, Joker is the largest, so to determine the rules of the game, literally can not compare size, do a conversion, according to the subscript to compare, return "345678910jqka2jokerjoker". indexOf (str);
    • First the size of the king is the largest, if present on the output, excluding the size of the king's case
    • Each type can be determined by length, the next is the bomb special, the bomb can be compared with various conditions, the first side is the bomb Lee side is not, output bombs
    • Apart from the bombs only the same length can be compared, the length is different, output error, the same length, compare the first number
Code:
 Public classMain { Public Static void Main(string[] args) {Scanner SC =NewScanner (System.inch);        String[] Left,right;        String[] Line; String nextline,outstring; while(Sc.hasnext ()) {nextline = Sc.nextline ();//have King blow up the king of the biggest            if(Nextline.contains ("Joker Joker") {outstring ="Joker Joker"; }Else{//Split first split into left and right then split into single rowline = Nextline.split ("-"); left = line[0].split (" "); right = line[1].split (" ");//Bomb Max                if(Left.length = =4&& Right.length! =4) {outstring = line[0]; }Else if(Right.length = =4&& Left.length! =4) {outstring = line[1]; }//card number in the case of the smallest card size, the Compare method returns the corresponding value of the card                Else if(Right.length = = left.length) {if(Count (left[0]) >count (right[0]) {outstring = line[0]; }Else{outstring = line[1]; }                      }Else{outstring ="ERROR"; }} System. out. println (outstring); }    }//2-joker returns 2-16 by size    Private Static int Count(String str) {return "345678910jqka2jokerjoker". indexOf (str); }}

Reference:
Http://www.nowcoder.com/test/question/done?tid=3641471&qid=25369#summary

My QR code is as follows, welcome to exchange discussion

You are welcome to pay attention to the "It question summary" subscription number. Every day to push the classic face test and interview tips, are dry! The QR code of the subscription number is as follows:

Huawei Machine Question "3"

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.