Go to diff to previous submission
#include <stdio.h> #include <stdlib.h> int RankToInt(char c) { switch(c) { case 'A': return 12; case 'K': return 11; case 'Q': return 10; case 'J': return 9; case 'X': return 8; default: return c - '2'; } } int SuitToInt(char c) { switch(c) { case 'h': return 0; case 'd': return 13; case 's': return 26; default: return 39; } } int Make(int a, int q = 0, int w = 0, int e = 0, int r = 0, int t = 0) { return (a << 20) | (q << 16) | (w << 12) | (e << 8) | (r << 4) | (t << 0); } int FindRank(int* r, int a, int prev = 13) { for(int i = prev - 1; 1; i--) { if(r[i] == a) { return i; } } } int Assess(int a[5]) { int r[13], rr[13]; for(int i = 0; i < 13; i++) { r[i] = 0; rr[i] = 0; } for(int i = 0; i < 5; i++) { r[a[i] % 13]++; } for(int i = 0; i < 13; i++) { rr[r[i]]++; } int flush = 1; for(int i = 1; i < 5; i++) { if(a[i] / 13 != a[0] / 13) { flush = 0; break; } } int q, w, e, u, t; for(int i = 12; i >= 3; i--) { int ok = 1; for(int j = 9; j <= 13; j++) { if(!(r[(i + j) % 13])) { ok = 0; break; } } if(ok) { return Make((flush) ? 8 : 4, i); } } if(rr[4]) { q = FindRank(r, 4); w = FindRank(r, 1); return Make(7, q, w); } if((rr[3]) && (rr[2])) { q = FindRank(r, 3); w = FindRank(r, 2); return Make(6, q, w); } if(rr[3]) { q = FindRank(r, 3); w = FindRank(r, 1); e = FindRank(r, 1, w); return Make(3, q, w, e); } if(rr[2] == 2) { q = FindRank(r, 2); w = FindRank(r, 2, q); e = FindRank(r, 1); return Make(2, q, w, e); } if(rr[2]) { q = FindRank(r, 2); w = FindRank(r, 1); e = FindRank(r, 1, w); t = FindRank(r, 1, e); return Make(1, q, w, e, t); } q = FindRank(r, 1); w = FindRank(r, 1, q); e = FindRank(r, 1, w); t = FindRank(r, 1, e); u = FindRank(r, 1, t); return Make((flush) ? 5 : 0, q, w, e, t, u); } int Player[20][2]; int Table[5]; char s[10]; int Septuple[20][7]; int a[5]; int choose[5]; int Value[20]; int Next() { int i; for(i = 4; i >= 0; i--) { choose[i]++; if(choose[i] < 3 + i) { break; } } if(i == -1) { return 0; } for(i++; i < 5; i++) { choose[i] = choose[i - 1] + 1; } return 1; } int main() { int n; while(scanf("%d", &n) > 0) { for(int i = 0; i < 5; i++) { scanf("%s", s); Table[i] = RankToInt(s[0]) + SuitToInt(s[1]); } for(int i = 0; i < n; i++) { for(int j = 0; j < 2; j++) { scanf("%s", s); Player[i][j] = RankToInt(s[0]) + SuitToInt(s[1]); } } for(int i = 0; i < 20; i++) { Value[i] = 0; } for(int i = 0; i < n; i++) { for(int j = 0; j < 5; j++) { Septuple[i][j] = Table[j]; } Septuple[i][5] = Player[i][0]; Septuple[i][6] = Player[i][1]; } /*for(int i = 0; i < 5; i++) { printf("%d ", Table[i]); } printf("\n"); for(int i = 0; i < n; i++) { for(int j = 0; j < 2; j++) { printf("%d ", Player[i][j]); } printf("\n"); }*/ for(int i = 0; i < 5; i++) { choose[i] = i; } while(1) { /*for(int i = 0; i < 5; i++) { printf("%d ", choose[i]); } printf("\n");*/ for(int i = 0; i < n; i++) { for(int j = 0; j < 5; j++) { a[j] = Septuple[i][choose[j]]; } int as = Assess(a); if(as > Value[i]) { Value[i] = as; } } if(!(Next())) { break; } } int max = 0; for(int i = 0; i < n; i++) { if(Value[i] > max) { max = Value[i]; } } int space = 0; for(int i = 0; i < n; i++) { if(Value[i] == max) { printf("%s%d", (space) ? " " : (space = 1, ""), i + 1); } } printf("\n"); } return 0; }