这个是判断的条件
if(有对王){ 对王大 }else{ if(长度相等){ 判断第一个的大小 }else{ if(有四个的炸弹){ 炸弹赢 }else{ 不符合规则 } } }
但是这里有个问题是既有文字又有数字,而且有可能出现10这个数字,所以最好是全部转成数字然后再去判断他们第一个数字的大小。
以下是题解
#include<iostream> using namespace std; char str1[15],str2[15],str[105]; int a[15],b[15],lena,lenb; int main(){ while(cin.getline(str,100)){ int flag=0,len1=0,len2=0; for(int i=0;str[i]!=0;i++){ if(str[i]=='-'){ flag=1; i++; } if(flag==0){ str1[len1++]=str[i]; }else{ str2[len2++]=str[i]; } } //拆到两个数字类型的数组里 if(len1==11){ cout<<str1<<endl; }else if(len2==11){ cout<<str2<<endl; }else{ lena=0,lenb=0; //处理数组变成数字类型数组 for(int i=0;i<len1;i++){ if(str1[i]=='A'){ a[lena++]=14; }else if(str1[i]=='J'){ a[lena++]=11; }else if(str1[i]=='Q'){ a[lena++]=12; }else if(str1[i]=='K'){ a[lena++]=13; }else if(str1[i]>='0'&&str1[i]<='9'){ int tmp=0; do{ tmp=tmp*10+str1[i]-'0'; i++; }while(str1[i]>='0'&&str1[i]<='9'); a[lena++]=tmp; } } for(int i=0;i<len2;i++){ if(str2[i]=='A'){ b[lenb++]=1; }else if(str2[i]=='J'){ b[lenb++]=11; }else if(str2[i]=='Q'){ b[lenb++]=12; }else if(str2[i]=='K'){ b[lenb++]=13; }else if(str2[i]>='0'&&str2[i]<='9'){ int tmp=0; do{ tmp=tmp*10+str2[i]-'0'; i++; }while(str2[i]>='0'&&str2[i]<='9'); b[lenb++]=tmp; } } if(lena==lenb){ if(a[0]>b[0]){ cout<<str1<<endl; }else{ cout<<str2<<endl; } }else if(lena==4){ cout<<str1<<endl; }else if(lenb==4){ cout<<str2<<endl; }else{ printf("ERROR\n"); } } } }