#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 1e5 + 5; // c: C0 D1 H2 S3 // id = c*13 + x (1,52) inline int transx(char c) { if (c == 'T') return 9; if (c == 'J') return 10; if (c == 'Q') return 11; if (c == 'K') return 12; if (c == 'A') return 13; return c - '1'; // 2->9 : 1->8 } inline int transc(char c) { if (c == 'C') return 0; if (c == 'D') return 1; if (c == 'H') return 2; if (c == 'S') return 3; } struct Tile { int x, c, id; friend bool operator<(Tile a, Tile b) { return a.x < b.x || a.x == b.x && a.c < b.c; } }; bool cmp(Tile a, Tile b) { return a.x > b.x || a.x == b.x && a.c < b.c; } inline int getid(int x, int c) { return c * 13 + x; } inline Tile getT(int id) { int x = (id - 1) % 13 + 1; int c = (id - 1) / 13; return (Tile){x, c, id}; } struct Hand { Tile t[5]; int id; bool IsFourOfAKind() { bool fla = 1, flb = 1; for (int i = 1; i < 4; i++) { if (t[i].x != t[i - 1].x) fla = 0; } for (int i = 2; i < 5; i++) { if (t[i].x != t[i - 1].x) flb = 0; } if (fla | flb) { if (t[0].x != t[1].x) { swap(t[0], t[4]); } } return fla | flb; } bool IsFullHouse() { bool fla = (t[0].x == t[1].x); bool flb = (t[3].x == t[4].x); if (fla && flb && (t[2].x == t[1].x || t[2].x == t[3].x)) { if (t[1].x != t[2].x) { sort(t, t + 5, cmp); } } return fla && flb && (t[2].x == t[1].x || t[2].x == t[3].x); } bool IsFlush() { bool samec = 1; for (int i = 1; i < 5; i++) { if (t[i].c != t[i - 1].c) { samec = 0; } } if (samec) { sort(t, t + 5, cmp); } return samec; } bool IsStright() { bool incre = 1; for (int i = 1; i < 5; i++) { if (t[i].x != t[i - 1].x + 1) { incre = 0; } } if (t[0].x == 1 && t[1].x == 2 && t[2].x == 3 && t[3].x == 4 && t[5].x == 13) incre = 1; return incre; } bool IsStrightFlush() { return IsStright() && IsFlush(); } bool IsRoyalFlush() { return IsStrightFlush() && t[0].x == 9; } bool IsThreeOfAKind() { bool fla = (t[0].x == t[1].x && t[1].x == t[2].x); bool flb = (t[1].x == t[2].x && t[2].x == t[3].x); bool flc = (t[2].x == t[3].x && t[3].x == t[4].x); if (flb) { swap(t[0], t[3]); sort(t + 3, t + 5); } if (flc) { swap(t[0], t[3]); swap(t[1], t[4]); sort(t + 3, t + 5); } return fla || flb || flc; } bool IsTwoPairs() { int cnt = 0; int p[2], z; for (int i = 1; i < 5; i++) { if (t[i].x == t[i - 1].x) { p[cnt] = t[i].x; cnt++; i++; } else z = t[i].x; } if (cnt == 2) { sort(p, p + 2); t[0].x = t[1].x = p[1]; t[2].x = t[3].x = p[0]; t[4].x = z; } return cnt == 2; } bool IsPair() { int cnt = 0; for (int i = 1; i < 5; i++) { if (t[i].x == t[i - 1].x) { swap(t[0], t[i]); swap(t[1], t[i - 1]); cnt = 1; break; } } return cnt == 1; } void trans() { if (IsRoyalFlush()) { id = 9; return; } if (IsStrightFlush()) { id = 8; return; } if (IsFourOfAKind()) { id = 7; return; } if (IsFullHouse()) { id = 6; return; } if (IsFlush()) { id = 5; return; } if (IsStright()) { id = 4; return; } if (IsThreeOfAKind()) { id = 3; return; } if (IsTwoPairs()) { id = 2; return; } if (IsPair()) { id = 1; return; } id = 0; return; } } a, b, pa, pb; // 1 win 2 lose 3 tie (self / a) bool vis[60]; void solve() { memset(vis, 0, sizeof vis); // read in for (int i = 0; i < 4; i++) { string s; cin >> s; int x = transx(s[0]), c = transc(s[1]); int id = getid(x, c); a.t[i] = (Tile){x, c, id}; vis[id] = 1; } for (int i = 0; i < 4; i++) { string s; cin >> s; int x = transx(s[0]), c = transc(s[1]); int id = getid(x, c); b.t[i] = (Tile){x, c, id}; vis[id] = 1; } // a:self b:opponent int ans = 1; for (int idb = 1; idb <= 52; idb++) { if (vis[idb]) continue; b.t[4] = getT(idb); vis[idb] = 1; int res = 2; for (int ida = 1; ida <= 52; ida++) { if (vis[ida]) continue; a.t[4] = getT(ida); vis[ida] = 1; for (int i = 0; i < 5; i++) { pa.t[i] = a.t[i]; } for (int i = 0; i < 5; i++) { pb.t[i] = b.t[i]; } sort(pa.t, pa.t + 5); sort(pb.t, pb.t + 5); pa.trans(); pb.trans(); int cur = 3; if (pa.id > pb.id) { cur = 1; } else if (pa.id < pb.id) { cur = 2; } else { for (int i = 0; i < 4; i++) { if (pa.t[i].x > pb.t[i].x) { cur = 1; } else if (pa.t[i].x < pb.t[i].x) { cur = 2; } } } if (cur == 1) { res = 1; break; } if (cur == 3) { res = 3; } vis[ida] = 0; } if (res == 2) { ans = 2; break; } if (res == 3) { ans = 3; } vis[idb] = 0; } if (ans == 1) { cout << "WoYaoYanPai\n"; } if (ans == 2) { cout << "GeiWoCaPiXie\n"; } if (ans == 3) { cout << "PaiMeiYouWenTi\n"; } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { solve(); } return 0; }
Note.ms
/137QWQ