主要是字符串处理,和各种情况判定,
#include <iostream>
#include <vector>
using namespace std;
int main() {
struct poker {
string s;
enum pk_type{error=0,one, two,three,five, boom,super} type;
const string tab="3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER";
vector<string> cards;
pk_type get_type() const {
int n=cards.size();
if (1==n) return one;
else if (2==n) {
if ("joker JOKER"==s) return super;
else return two;
}
else if (3==n) return three;
else if (4==n) return boom;
else if (5==n) return five;
return error;
}
int operator < (const poker& b) {
poker &a=*this;
auto pos_a=tab.find(a.cards[0]);
auto pos_b=tab.find(b.cards[0]);
if(one==a.type && one==b.type || two==a.type && two==b.type||
three==a.type&&three==b.type||five==a.type&&five==b.type) return pos_a<pos_b;
else if (super==a.type) return false;
else if (super==b.type) return true;
else if (boom==a.type) {
if(boom==b.type) return pos_a<pos_b;
else return false;
}
else if (boom==b.type) return true;
return 2;
}
void put_cards() {
string tmp="";
for (auto i=0;i<s.size();i++) {
if (' '==s[i]) {
cards.push_back(tmp);
tmp="";
}
tmp+=s[i];
}
cards.push_back(tmp);
}
poker(string& a):s(a) {
put_cards();
type=this->get_type();
}
};
string s;
getline(cin, s);
auto pos=s.find('-');
string s1=s.substr(0,pos);
string s2=s.substr(pos+1);
poker a(s1),b(s2);
int res= a<b;
if (1==res) cout<<b.s;
else if (0==res) cout << a.s;
else cout << "ERROR";
}