题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
#include <iostream> using namespace std; int getValue(char s) { if (s == '2') return 15; if (s == 'A') return 14; if (s == 'K') return 13; if (s == 'Q') return 12; if (s == 'J') return 11; if (s == '1') return 10; //只有10开头是1,所以用1代替10; else return (s - '3' + 3); } int main() { string str; getline(cin, str); string str1 = str.substr(0, str.find('-')); string str2 = str.substr(str.find('-') + 1); for (int i = 0; i < str1.length(); i++) { if (str1[i] == '0') str1.erase(i, 1); } for (int i = 0; i < str2.length(); i++) { if (str2[i] == '0') str2.erase(i, 1); } int l1 = str1.length(); int l2 = str2.length(); if (l1 == 11 || l2 == 11) { cout << "joker JOKER" << endl; } else if (l1 == 7 && l2 != 7) { if (str1[0] == '1') cout << "10 10 10 10" << endl; else cout << str1 << endl; } else if (l1 != 7 && l2 == 7) { if (str2[0] == '1') cout << "10 10 10 10" << endl; else cout << str2 << endl; } else if (str1 == "JOKER" || str2 == "JOKER") { cout << "JOKER" << endl; } else if (str1 == "joker" || str2 == "joker") { cout << "joker" << endl; } else if (l1 != l2) cout << "ERROR" << endl; else { for (int i = 0; i < str1.length(); i++) { if (str1[i] == '1') str1.insert(i + 1, 1, '0'); } for (int i = 0; i < str2.length(); i++) { if (str2[i] == '1') str2.insert(i + 1, 1, '0'); } if (getValue(str1[0]) < getValue(str2[0])) { cout << str2 << endl; } else cout << str1 << endl; } }