华子第一题的难度,限制条件分析清楚就可以
#include<stdio.h>
#include<string.h>
char str1[15]={0};
char str2[15]={0};
int func(char c){
switch(c){
case '3':return 1;
case '4':return 2;
case '5':return 3;
case '6':return 4;
case '7':return 5;
case '8':return 6;
case '9':return 7;
case '1':return 8;
case 'J':return 9;
case 'Q':return 10;
case 'K':return 11;
case 'A':return 12;
case '2':return 13;
}
return 0;
}
void compare(char a,char b)
{
int temp1=func(a);
int temp2=func(b);
if(temp1>temp2){printf("%s",str1);return ;}
else{printf("%s",str2);return ;}
}
int main(void)
{
scanf("%[^-]",&str1);
getchar();
scanf("%[^\n]",&str2);
int len1=strlen(str1);
int len2=strlen(str2);
if(strcmp(str1,"joker JOKER")==0){printf("%s\n",str1);return 0;}
if(strcmp(str2,"joker JOKER")==0){printf("%s\n",str2);return 0;}
if(strcmp(str1,"joker")==0)
{
if(strcmp(str2,"JOKER")==0){printf("%s\n",str2);return 0;}
if(len2==1||len2==2){printf("%s\n",str1);return 0;}
else{printf("ERROR");return 0;}
}
if(strcmp(str1,"JOKER")==0)
{
if(strcmp(str2,"joker")==0){printf("%s\n",str1);return 0;}
if(len2==1||len2==2){printf("%s\n",str1);return 0;}
else{printf("ERROR");return 0;}
}
if(len1==7||(len1==11&str1[0]=='1'))//1为炸弹
{
if(len2==7||(len2==11&str2[0]=='1'))//2也是炸弹
{
compare(str1[0],str2[0]);
return 0;
}
else//2非炸弹
{
printf("%s\n",str1);
return 0;
}
}
if(len2==7||(len2==11&str2[0]=='1'))//1为炸弹
{
if(len1==7||(len1==11&str1[0]=='1'))//2也是炸弹
{
compare(str1[0],str2[0]);
return 0;
}
else//1非炸弹
{
printf("%s\n",str2);
return 0;
}
}
if(len1==1||len1==2)//不带王的单牌
{
if(strcmp(str2,"joker")==0||strcmp(str2,"JOKER")==0)
{printf("%s",str2);return 0;}
if(len2>2){printf("ERROR");return 0;}
if(len2==2||len2==1)
{
compare(str1[0],str2[0]);
return 0;
}
}
if(len1==3||(len1==5&&str1[0]=='1'))//对子,一副牌没有对王
{
if(len2==3||(len2==5&&str2[0]=='1'))//2也是对子
{
compare(str1[0],str2[0]);
return 0;
}
else{printf("ERROR");return 0;}
}
if(len1==5||(len1==8&&str1[0]=='1'))//3张牌
{
if(len2==5||(len2==8&&str2[0]=='1'))
{
compare(str1[0],str2[0]);
return 0;
}
else{printf("ERROR");return 0;}
}
if(len1==9||len1==10)//顺子
{
if(len2==9||len2==10)
{
compare(str1[0],str2[0]);
return 0;
}
else{printf("ERROR");return 0;}
}
return 0;
}

京公网安备 11010502036488号