C语言实现斗地主牌型判断:三带一
感谢您的说明,以下是根据您的要求进行修改后的C语言代码示例:
#include <stdio.h>
#include <stdbool.h>
bool isThreeWithOne(char hand[]) {
int counts[13] = {0}; // 记录每个牌面的数量
for (int i = 0; i < 4; i++) {
char card = hand[i];
if (card >= '2' && card <= '9') {
counts[card - '2']++;
} else {
switch (card) {
case 'A':
counts[0]++;
break;
case 'X':
counts[9]++;
break;
case 'J':
counts[10]++;
break;
case 'Q':
counts[11]++;
break;
case 'K':
counts[12]++;
break;
}
}
}
int threeCount = 0;
int oneCount = 0;
for (int i = 0; i < 13; i++) {
if (counts[i] == 3) {
threeCount++;
} else if (counts[i] == 1) {
oneCount++;
} else if (counts[i] == 4) {
return false; // 四炸牌型不属于三带一牌型
}
}
return (threeCount == 1) && (oneCount == 1);
}
int main() {
int T;
scanf("%d", &T);
for (int i = 0; i < T; i++) {
char hand[5];
scanf("%s", hand);
if (isThreeWithOne(hand)) {
printf("yes\n");
} else {
printf("no\n");
}
}
return 0;
}
在这个修正后的代码中,我们对判断函数isThreeWithOne进行了进一步修改。现在,我们会检查牌面计数器是否等于4,如果等于4,则直接返回false,表示不属于“三带一”牌型中的四炸牌型。
在main函数中,我们首先读取输入的轮数T,然后通过循环依次处理每一轮的手牌。对于每一轮,我们调用isThreeWithOne函数判断手牌是否为“三带一”牌型,根据判断结果输出相应的结果。
希望以上代码满足您的要求。如果您还有其他问题,请随时提问。
原文地址: https://www.cveoy.top/t/topic/0CG 著作权归作者所有。请勿转载和采集!