How to ask for the smooth of poker

Source: Internet
Author: User
Tags bool hash include printf sort

Topic Description:

ll today in a particularly good mood, because he went to buy a deck of poker, found inside incredibly there are 2 Kings, 2 small Wang (a deck is originally 54 Zhang ^_^) ... He randomly out of 5 cards, want to test their own luck, see if you can smoke to shun son, if smoked, he decided to buy sports lottery, hey!! "Hearts A, Spades 3, Xiao Wang, king, Square piece 5", "Oh my god!" Not shun son ... ll not happy, he thought, decided that big \ Xiao Wang can be seen as any number, and a as 1,j for 11,q for 12,k 13. The top 5 cards can be turned into "1,2,3,4,5" (2 and 4, respectively), "so lucky!". ll decide to buy the sports lottery.

Now, ask you to use this card to simulate the above process, and then tell us how lucky ll is. For the sake of convenience, you may think that king size is 0.

Input:

Multiple sets of data are entered.

Each group of data contains two rows, and the first line enters a positive n (0<=n<=14) that represents the number of cards pulled from the poker. The next line enters the number of N, representing the cards drawn from the deck. If n=0, the input is ended.

Output:

corresponding to each group of data, if the card drawn is CIS, then output "so lucky!". Otherwise, the output "Oh my god!".

Sample input:

5

3 5 1 0 4

5

3 5 4 7 6

5

3 5 7 4 8

0

Sample output:

So lucky!

So lucky!

Oh my god!

Nine degrees to change the title to a deck of cards have 4 king size, here, regardless of its up to a few 0, on the topic, not rigorous, very vague, such as there is no more rigorous definition of shun son, 5 of the following consecutive number is a shun son? In reality, it takes at least 5 to be a straight one, and if you assume that 3 cards are the same, it's a bit far-fetched if you're typing 3 0. Look at the forum a lot of people spit groove. Anyhow, no matter how much, this topic no matter how it pit Dad, use the sword to refer to the idea of the offer on the code AC is no problem, because here no matter how many you 0 (as long as the length of the array is not greater than can be) ok.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

I wanted to avoid sorting, or to open hash arrays, to traverse to find the maximum, the minimum, 0 the number of occurrences, and then based on the relationship between the three to determine whether a CIS, but this will be in the array without repeating elements of the premise, but to determine the array has no duplicate elements, or to sort, or the number of times the element appears with the help of a hash array will eventually save you. But finally still use the book of ideas, in order to find the simplicity of the code, as the C language with the quick sort function, of course, with the counting sort (in fact, with the opening of the hash array is a way of thinking) faster, but for n the maximum of 14, the efficiency of the two is not too much.

AC Code:

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> int my  
Compare (const void *data1,const void *data2) {return * (int *) data1-* (int *) data2;  
      
    BOOL Iscontinuous (int *arr,int len) {if (Arr==null | | | len<1) return FALSE;  
      
    Qsort (arr,len,sizeof (int), mycompare);     int NumOf0 = 0;  Number of 0 int numofgap = 0;  
    Number of vacancies int i;  
        for (i=0;i<len-1;i++) {if (arr[i] = = 0) numof0++;  
            else {if (arr[i] = = Arr[i+1]) return false;  
        else numofgap + = arr[i+1]-arr[i]-1;  
} return (numofgap>numof0)? False:true;  
    int main () {int n;  
    int arr[15];  
    memset (arr,0,sizeof (arr));  
        while (scanf ("%d", &n)!=eof && n!=0) {int i; for (i=0;i<n;i++) SCANF ("%d", arr+i);  
        BOOL can = iscontinuous (arr,n);  
        if (CAN) printf ("So lucky!\n");  
    else printf ("Oh my god!\n");  
return 0; }

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.