Solving notes (17) -- playing cards

Source: Internet
Author: User

Problem description: randomly draw 5 cards from the playing cards to determine whether the cards are continuous or not. 2-10 is the number itself, a is 1, J is 11, Q is 12, K is 13, and the king of size can be seen as any number.

Idea: You can sort these five cards in order, and then calculate the number of 0 and the number of intervals between non-0 numbers. If there is a repeated non-0 number, it is not a good choice. If the number of intervals is less than or equal to 0, it is a forward slash. I have not come up with a better solution for the moment.

Reference code:

// Function: Randomly draws 5 cards from a playing card to determine whether the card is a good character. // function parameter: The number of cards for pcards and the number of cards for nlen // return value: whether to use bool iscontinuous (int * pcards, int nlen) {If (pcards = NULL | nlen <= 0) return false; sort (pcards, pcards + nlen ); // call the Sorting Algorithm int I of the standard library; int zerocount = 0; // use 0 to indicate int capcount = 0; // Number of intervals // count the number of zeros for (I = 0; I <nlen; I ++) {If (pcards [I] = 0) zerocount ++; elsebreak;} // statistics interval int precard = pcards [I]; for (I = I + 1; I <nlen; I ++) {int curcard = Pcards [I]; If (precard = curcard) // compare with the previous card return false; elsecapcount + = curcard-precard-1; // Number of accumulated intervals precard = curcard;} return (zerocount> = capcount )? True: false; // as long as the number of kings exceeds the interval}

I enjoy the copyright of blog articles, reprint please indicate the source http://blog.csdn.net/wuzhekai1985

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.