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