题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
#include <iostream> #include <string> using namespace std; int getvalue(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; //用1代替10 case 'J': return 9; case 'Q': return 10; case 'K': return 11; case 'A': return 12; case '2': return 13; } return 0; } int main() { string strs; getline(cin ,strs); string str1 = strs.substr(0,strs.find('-')); string str2 = strs.substr(strs.find('-') + 1,strs.size() - 1); int space1 = 0; int space2 = 0; for (int i = 0;i < str1.size();i++) { if (str1[i] == ' ') { space1 += 1; } } for (int i = 0;i < str2.size();i++) { if (str2[i] == ' ') { space2 += 1; } } //cout << str1 << ' ' << str2 << ' ' << space1 << ' ' << space2 << endl; if (str1 == "joker JOKER" || str2 == "joker JOKER") { cout << "joker JOKER" ; } else if (space1 == 3 && space2 == 3) { if (getvalue(str1) > getvalue(str2)) { cout << str1; } else { cout << str2; } } else if (space1 == 3) { cout << str1; } else if (space2 == 3) { cout << str2; } else if (space1 == space2) { if (str1 == "joker") { if (str2 == "JOKER") { cout << str2; } else { cout << str1; } } else if (str2 == "joker") { if (str1 == "JOKER") { cout << str1; } else { cout << str2; } } else if (getvalue(str1) > getvalue(str2)) { cout << str1; } else { cout << str2; } } else { cout << "ERROR"; } } // 64 位输出请用 printf("%lld")