/* This has the same effect and internal structure as poker3, but it uses arrays for related variables, and an array for the names of ranks 2, 3, ..., A. Try looking at this program in one editor window, and poker3.c in another editor window, at the same time. Do you see how to modify poker3.c to obtain poker7.c? */ #include char rc[13] = { '2','3','4','5','6','7','8','9','T','J','Q','K','A' }; long long value_hand(char r[5],char s[5]) { long long result; int flush; int have[13]; /* have[i] is the number of cards with rank rc[i] */ char straight; /* the highest rank in a straight; 0 if not straight */ int reps[6]; /* reps[2] is the number of pairs, reps[3] threes, etc. */ flush = (s[0] == s[1] && s[1] == s[2] && s[2] == s[3] && s[3] == s[4]); have[0] = (r[0] == rc[0]) + (r[1] == rc[0]) + (r[2] == rc[0]) + (r[3] == rc[0]) + (r[4] == rc[0]); have[1] = (r[0] == rc[1]) + (r[1] == rc[1]) + (r[2] == rc[1]) + (r[3] == rc[1]) + (r[4] == rc[1]); have[2] = (r[0] == rc[2]) + (r[1] == rc[2]) + (r[2] == rc[2]) + (r[3] == rc[2]) + (r[4] == rc[2]); have[3] = (r[0] == rc[3]) + (r[1] == rc[3]) + (r[2] == rc[3]) + (r[3] == rc[3]) + (r[4] == rc[3]); have[4] = (r[0] == rc[4]) + (r[1] == rc[4]) + (r[2] == rc[4]) + (r[3] == rc[4]) + (r[4] == rc[4]); have[5] = (r[0] == rc[5]) + (r[1] == rc[5]) + (r[2] == rc[5]) + (r[3] == rc[5]) + (r[4] == rc[5]); have[6] = (r[0] == rc[6]) + (r[1] == rc[6]) + (r[2] == rc[6]) + (r[3] == rc[6]) + (r[4] == rc[6]); have[7] = (r[0] == rc[7]) + (r[1] == rc[7]) + (r[2] == rc[7]) + (r[3] == rc[7]) + (r[4] == rc[7]); have[8] = (r[0] == rc[8]) + (r[1] == rc[8]) + (r[2] == rc[8]) + (r[3] == rc[8]) + (r[4] == rc[8]); have[9] = (r[0] == rc[9]) + (r[1] == rc[9]) + (r[2] == rc[9]) + (r[3] == rc[9]) + (r[4] == rc[9]); have[10] = (r[0] == rc[10]) + (r[1] == rc[10]) + (r[2] == rc[10]) + (r[3] == rc[10]) + (r[4] == rc[10]); have[11] = (r[0] == rc[11]) + (r[1] == rc[11]) + (r[2] == rc[11]) + (r[3] == rc[11]) + (r[4] == rc[11]); have[12] = (r[0] == rc[12]) + (r[1] == rc[12]) + (r[2] == rc[12]) + (r[3] == rc[12]) + (r[4] == rc[12]); straight = 0; if (have[12] && have[0] && have[1] && have[2] && have[3]) straight = 5; if (have[0] && have[1] && have[2] && have[3] && have[4]) straight = 6; if (have[1] && have[2] && have[3] && have[4] && have[5]) straight = 7; if (have[2] && have[3] && have[4] && have[5] && have[6]) straight = 8; if (have[3] && have[4] && have[5] && have[6] && have[7]) straight = 9; if (have[4] && have[5] && have[6] && have[7] && have[8]) straight = 10; if (have[5] && have[6] && have[7] && have[8] && have[9]) straight = 11; if (have[6] && have[7] && have[8] && have[9] && have[10]) straight = 12; if (have[7] && have[8] && have[9] && have[10] && have[11]) straight = 13; if (have[8] && have[9] && have[10] && have[11] && have[12]) straight = 14; if (straight && flush) return 80000000000LL + straight; if (straight) return 40000000000LL + straight; result = 0; reps[5] = 0; if (have[12] == 5) { result = result * 100 + 14; ++reps[5]; } if (have[11] == 5) { result = result * 100 + 13; ++reps[5]; } if (have[10] == 5) { result = result * 100 + 12; ++reps[5]; } if (have[9] == 5) { result = result * 100 + 11; ++reps[5]; } if (have[8] == 5) { result = result * 100 + 10; ++reps[5]; } if (have[7] == 5) { result = result * 100 + 9; ++reps[5]; } if (have[6] == 5) { result = result * 100 + 8; ++reps[5]; } if (have[5] == 5) { result = result * 100 + 7; ++reps[5]; } if (have[4] == 5) { result = result * 100 + 6; ++reps[5]; } if (have[3] == 5) { result = result * 100 + 5; ++reps[5]; } if (have[2] == 5) { result = result * 100 + 4; ++reps[5]; } if (have[1] == 5) { result = result * 100 + 3; ++reps[5]; } if (have[0] == 5) { result = result * 100 + 2; ++reps[5]; } reps[4] = 0; if (have[12] == 4) { result = result * 100 + 14; ++reps[4]; } if (have[11] == 4) { result = result * 100 + 13; ++reps[4]; } if (have[10] == 4) { result = result * 100 + 12; ++reps[4]; } if (have[9] == 4) { result = result * 100 + 11; ++reps[4]; } if (have[8] == 4) { result = result * 100 + 10; ++reps[4]; } if (have[7] == 4) { result = result * 100 + 9; ++reps[4]; } if (have[6] == 4) { result = result * 100 + 8; ++reps[4]; } if (have[5] == 4) { result = result * 100 + 7; ++reps[4]; } if (have[4] == 4) { result = result * 100 + 6; ++reps[4]; } if (have[3] == 4) { result = result * 100 + 5; ++reps[4]; } if (have[2] == 4) { result = result * 100 + 4; ++reps[4]; } if (have[1] == 4) { result = result * 100 + 3; ++reps[4]; } if (have[0] == 4) { result = result * 100 + 2; ++reps[4]; } reps[3] = 0; if (have[12] == 3) { result = result * 100 + 14; ++reps[3]; } if (have[11] == 3) { result = result * 100 + 13; ++reps[3]; } if (have[10] == 3) { result = result * 100 + 12; ++reps[3]; } if (have[9] == 3) { result = result * 100 + 11; ++reps[3]; } if (have[8] == 3) { result = result * 100 + 10; ++reps[3]; } if (have[7] == 3) { result = result * 100 + 9; ++reps[3]; } if (have[6] == 3) { result = result * 100 + 8; ++reps[3]; } if (have[5] == 3) { result = result * 100 + 7; ++reps[3]; } if (have[4] == 3) { result = result * 100 + 6; ++reps[3]; } if (have[3] == 3) { result = result * 100 + 5; ++reps[3]; } if (have[2] == 3) { result = result * 100 + 4; ++reps[3]; } if (have[1] == 3) { result = result * 100 + 3; ++reps[3]; } if (have[0] == 3) { result = result * 100 + 2; ++reps[3]; } reps[2] = 0; if (have[12] == 2) { result = result * 100 + 14; ++reps[2]; } if (have[11] == 2) { result = result * 100 + 13; ++reps[2]; } if (have[10] == 2) { result = result * 100 + 12; ++reps[2]; } if (have[9] == 2) { result = result * 100 + 11; ++reps[2]; } if (have[8] == 2) { result = result * 100 + 10; ++reps[2]; } if (have[7] == 2) { result = result * 100 + 9; ++reps[2]; } if (have[6] == 2) { result = result * 100 + 8; ++reps[2]; } if (have[5] == 2) { result = result * 100 + 7; ++reps[2]; } if (have[4] == 2) { result = result * 100 + 6; ++reps[2]; } if (have[3] == 2) { result = result * 100 + 5; ++reps[2]; } if (have[2] == 2) { result = result * 100 + 4; ++reps[2]; } if (have[1] == 2) { result = result * 100 + 3; ++reps[2]; } if (have[0] == 2) { result = result * 100 + 2; ++reps[2]; } if (have[12] == 1) result = result * 100 + 14; if (have[11] == 1) result = result * 100 + 13; if (have[10] == 1) result = result * 100 + 12; if (have[9] == 1) result = result * 100 + 11; if (have[8] == 1) result = result * 100 + 10; if (have[7] == 1) result = result * 100 + 9; if (have[6] == 1) result = result * 100 + 8; if (have[5] == 1) result = result * 100 + 7; if (have[4] == 1) result = result * 100 + 6; if (have[3] == 1) result = result * 100 + 5; if (have[2] == 1) result = result * 100 + 4; if (have[1] == 1) result = result * 100 + 3; if (have[0] == 1) result = result * 100 + 2; if (reps[5]) return 90000000000LL + result; if (reps[4]) return 70000000000LL + result; if (reps[3] && reps[2]) return 60000000000LL + result; if (flush) return 50000000000LL + result; if (reps[3]) return 30000000000LL + result; if (reps[2] > 1) return 20000000000LL + result; if (reps[2]) return 10000000000LL + result; return result; } void rank_print(int n) { char c; switch (n) { case 14: c = rc[12]; break; case 13: c = rc[11]; break; case 12: c = rc[10]; break; case 11: c = rc[9]; break; case 10: c = rc[8]; break; case 9: c = rc[7]; break; case 8: c = rc[6]; break; case 7: c = rc[5]; break; case 6: c = rc[4]; break; case 5: c = rc[3]; break; case 4: c = rc[2]; break; case 3: c = rc[1]; break; case 2: c = rc[0]; break; default: c = '?'; break; /* should never happen */ } printf("%c",c); } void value_print(long long v) { if (v == 80000000014LL) { printf("royal flush.\n"); return; } switch (v / 10000000000LL) { case 9: printf("five "); rank_print(v % 100); printf("'s.\n"); return; case 8: printf("straight flush, "); rank_print(v % 100); printf(" high.\n"); return; case 7: printf("four "); rank_print((v / 100) % 100); printf("'s"); break; case 6: printf("three "); rank_print((v / 100) % 100); printf("'s. pair of "); rank_print(v % 100); printf("'s. full house. \n"); return; case 4: printf("straight, "); rank_print(v % 100); printf(" high.\n"); return; case 3: printf("three "); rank_print((v / 10000) % 100); printf("'s. "); rank_print((v / 100) % 100); break; case 2: printf("pair of "); rank_print((v / 10000) % 100); printf("'s. pair of "); rank_print((v / 100) % 100); printf("'s"); break; case 1: printf("pair of "); rank_print((v / 1000000) % 100); printf("'s. "); rank_print((v / 10000) % 100); printf(". "); rank_print((v / 100) % 100); break; case 5: printf("flush. "); /* fall through */ default: rank_print((v / 100000000) % 100); printf(". "); rank_print((v / 1000000) % 100); printf(". "); rank_print((v / 10000) % 100); printf(". "); rank_print((v / 100) % 100); } printf(". "); rank_print(v % 100); printf(". \n"); } int main(void) { char x[5]; char y[5]; for (;;) { if (scanf(" %c%c",&x[0],&y[0]) < 2) break; if (scanf(" %c%c",&x[1],&y[1]) < 2) break; if (scanf(" %c%c",&x[2],&y[2]) < 2) break; if (scanf(" %c%c",&x[3],&y[3]) < 2) break; if (scanf(" %c%c",&x[4],&y[4]) < 2) break; printf("%c%c ",x[0],y[0]); printf("%c%c ",x[1],y[1]); printf("%c%c ",x[2],y[2]); printf("%c%c ",x[3],y[3]); printf("%c%c: ",x[4],y[4]); value_print(value_hand(x,y)); } return 0; }