解题思路:先判断是不是王牌花色,如果都是,或者都不是才比较点数。
参考代码:
#include<stdio.h> #include<string.h> int dianshu(char *play) //计算牌的点数 { int n; int len=strlen(play); if(len==3) n=10; /*长度为3,牌号肯定是10*/ else if(len==2) { if (play[0] >= '2'&& play[0] <= '9') n=play[0]-'0'; else if (play[0] == 'A') n=1; else if (play[0] == 'J') n=11; else if (play[0] == 'Q') n=12; else if (play[0] == 'K') n=13; } return n; } int main() { int n,i,len1,len2; char key; char play1[5],play2[5]; scanf("%d",&n); for(i=0;i<n;i++) { getchar(); scanf("%c",&key); getchar(); scanf("%s%s",play1,play2); len1=strlen(play1); len2=strlen(play2); if((play1[len1-1]==key && play2[len2-1]==key) || (play1[len1-1]!=key && play2[len2-1]!=key)) //两张都是王牌花色或者都不是王牌花色 { if(dianshu(play1)-dianshu(play2)>0) printf("YES\n"); else printf("NO\n"); } else if(play1[len1-1]==key) printf("YES\n"); else if(play2[len2-1]==key) printf("NO\n"); } return 0; }
0.0分
0 人评分