# C语言题目：斗地主（给定n张牌，判断能不能一次出完）

5
2 J1 J2
4 A A A 5
5 A A A 5 6
6 A A A A 5 5
5 10 J Q K A

## Sample Output

Case #1: Yes
Case #2: Yes
Case #3: No
Case #4: Yes
Case #5: Yes

### 相关代码

``````#include<stdio.h>
#include<string.h>
#include<stdbool.h>
struct{
int count;
char pok[5];
}pok[]={
{0,"2"},{0,"3"},{0,"4"},{0,"5"},{0,"6"},
{0,"7"},{0,"8"},{0,"9"},{0,"10"},{0,"J"},
{0,"Q"},{0,"K"},{0,"A"},{0,"J1"},{0,"J2"}
};
int Shun(int n,int m){
int i,j;
for(i = 1;i <= 12 - n;i++){
if(pok[i].count == m){
for(j = 0;j < n;j++){
if(pok[i+j].count!=m){
return 0;
}
}
return 1;
}
}
}
void main(){
char a[20][5];
int co,t,n,i,j,k,is;
scanf("%d",&t);
for(co = 1;co <= t;co++){
is = 0;
for(i = 0;i<15;i++){
pok[i].count = 0;
}
scanf("%d",&n);
for(j = 0;j < n;j++){
scanf("%s",a[j]);
for(k = 0;k < 15;k++){
if(strcmp(pok[k].pok,a[j]) == 0){
pok[k].count++;
}
}
}
int p4 = 0,p3 = 0,p2 = 0,p1 = 0;
for(k = 0;k < 15;k++){
if(pok[k].count == 2)p2++;
if(pok[k].count == 3)p3++;
if(pok[k].count == 4)p4++;
if(pok[k].count == 1)p1++;
}
is = 0;
switch(n){
case 1:is = 1;break;
case 2:{if(p2 == 1)is = 1;else if(pok[13].count == 1&&pok[14].count == 1)is = 1;break;}
case 3:{if(p3 == 1)is = 1;break;}
case 4:{if(p4 == 1)is = 1;else if(p3 == 1)is = 1;break;}
case 5:{
if(p3 == 1&&p2 == 1){
is = 1;
}else if(p3 == 1&&p2==0)is = 0;
else if(Shun(5,1)){is = 1;}break;}
case 6:{
if(p4 == 1)is = 1;    //四带二
else if(p1 == 6&&Shun(6,1)){is = 1;}   //顺子
else if(p2 == 3&&Shun(3,2)){is = 1;}    //3+3
else if(p3 == 2&&Shun(2,3)){is = 1;}   //连对
break;
}
case 7:{if(p1 == 7&&Shun(7,1)){is = 1;} break;}
case 8:{if(p1 == 8&&Shun(8,1)){is = 1;}     //顺子
else if(p2 == 4&&Shun(4,2)){is = 1;}    //连对
else if(p3 == 2&&Shun(3,2)){is = 1;}   //飞机带翅膀
else if(p4 == 1&&p2 == 2){is = 1;}     //四带二
else if(p4 == 2){is = 1;}
break;
}
case 9:{if(p1 == 9&&Shun(9,1)){is = 1;}
else if(p3 == 3&&Shun(3,3)){is = 1;}
break;
}
case 10:{if(p1 == 10&&Shun(10,1)){is = 1;}
else if(p2 == 5&&Shun(5,2)){is = 1;}
break;
}
case 11:{if(p1 == 11&&Shun(11,1)){is = 1;}break;}
case 12:{if(p1 == 12&&Shun(12,1)){is = 1;}
else if(p2 == 6&&Shun(6,2)){is = 1;}
else if(p3 == 3&&Shun(3,3)){is = 1;}
break;
}
case 13:{if(p1 == 13&&Shun(13,1)){is = 1;}break;}
case 14:{if(p2 == 7&&Shun(7,2)){is = 1;}break;}
case 15:{if(p3 == 3&&p2 == 3){is = 1;}break;}
case 16:{if(p2 == 8&&Shun(8,2)){is = 1;}
else if(p3 == 4&&Shun(4,3)){is = 1;}break;}
case 17:{is = 0;break;}
case 18:{if(p2 == 9&&Shun(9,2)){is = 1;}break;}
case 19:{is = 0;break;}
case 20:{if(p3 == 4&&p2 == 4){is = 1;}break;}
}
if(is){
char str[4] = "Yes";
printf("Case #%d: %sn",co,str);
}
else {
char str[4] = "No";
printf("Case #%d: %sn",co,str);
}
}
}``````

## 回答

``2 J1 J2``

``5 A A A 5 6``