题解 | #扑克牌大小#修改大佬bug
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb?tpId=37&tqId=21311&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <iostream> #include <string> using namespace std; int getrank(string s); int main() { string s; while(getline(cin,s)) { string s1=s.substr(0,s.find('-')); string s2=s.substr(s.find('-')+1); int space1=0,space2=0; for(int i=0;i<s1.length();i++) { if(s1[i]==' ') space1++; } for(int i=0;i<s2.length();i++) { if(s2[i]==' ') space2++; } if(s1=="joker JOKER"||s2=="joker JOKER") cout<<"joker JOKER"<<endl; else if(space1==3&&space2==3)//炸弹 { if(getrank(s1)>getrank(s2)) cout<<s1<<endl; else cout<<s2<<endl; } else if(space1==3)cout<<s1<<endl; else if(space2==3) cout<<s2<<endl; else if(space1==space2) //没有炸弹 { if((s1=="JOKER")||(s2=="JOKER")) cout<<"JOKER"<<endl; //如果单张大王 else { if(getrank(s1)>getrank(s2)) cout<<s1<<endl; else cout<<s2<<endl; }; } else { cout<<"ERROR"<<endl; } } } int getrank(string s) { switch (s[0]) { 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; case 'j':return 14; } return -1; } // 64 位输出请用 printf("%lld")