C:检查一组五张卡是否构成满堂红

时间:2017-10-21 17:56:12

标签: c

这是我的代码:

#include <stdio.h>

int main(void) {
    int i;
    int num[13] = {0};
    char poker[5];

    // input a set of five cards
    for (i = 0; i < 5; i++) {
        scanf(" %c", &poker[i]);
    }

    for (i = 0; i < 5; i++) {
        if (poker[i] == '10') num[9]++;  // how do I modify this line?
        if (poker[i] == 'J')  num[10]++;
        if (poker[i] == 'Q')  num[11]++;
        if (poker[i] == 'K')  num[12]++;
        if (poker[i] == 'A')  num[0]++;
        if (poker[i] >= '2' && poker[i] <= '9') {
            num[poker[i] - '0' - 1]++;
        }
    }

    int check = 1;

    for (i = 0; i < 13; i++) {
        // if num[i] != 2 or 3 then it's not full house
        if (num[i] == 1 || num[i] > 3) {
            check = 0;
        }
    }

    if (check) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

除了包含'10'的输入数据外,一切正常。

示例stdin

10 10 10 K A

预期标准输出

NO

但是,我的程序会认为它是满堂红。

我认为它出错的原因是“10”实际上不是一个角色。

有没有办法修改我的代码并解决这个问题?

谢谢!

1 个答案:

答案 0 :(得分:2)

尝试使用其他字符代表10,例如'T'