1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| #include <iostream> #include <string> #include <unordered_map> using namespace std;
unordered_map<char, int> map;
int getNumber(string card, char& color) { color = card[card.size() - 1]; int number = 0; if (card.size() == 3) number = 10; else number = map[card[0]];
return number; }
void probability(string* cards, int& up, int& down) { int numbers[4]; bool sameColor = true; char color = ' '; for (int i = 0; i < 4; i++) { char colorTmp; numbers[i] = getNumber(cards[i], colorTmp); if (color != ' ' && colorTmp != color) sameColor = false; color = colorTmp; }
for (int i = 0; i < 4; i++) { int minN = numbers[i]; int minI = i; for (int j = i; j < 4; j++) { if (numbers[j] < minN) { minN = numbers[j]; minI = j; } } numbers[minI] = numbers[i]; numbers[i] = minN; } if (numbers[0] == 1 && (numbers[1] == 11 && numbers[2] == 12 && numbers[3] == 13) || (numbers[1] == 2 && numbers[2] == 3 && numbers[3] == 4) || (numbers[1] == 10 && numbers[2] == 11 && numbers[3] == 12) || (numbers[1] == 10 && numbers[2] == 11 && numbers[3] == 13) || (numbers[1] == 10 && numbers[2] == 12 && numbers[3] == 13)) { if (sameColor) { up = 1; down = 16; } else { up = 1; down = 12; } return; }
bool straight = true; for (int i = 0; i < 3; i++) if (numbers[i + 1] - numbers[i] != 1) { straight = false; break; }
if (straight) { if (sameColor) { up = 1; down = 8; } else { up = 1; down = 6; } } else { bool unStraight = false; for (int i = 0; i < 3; i++) { if (numbers[i + 1] - numbers[i] == 2) { if (!unStraight) unStraight = true; else { unStraight = false; break; } } else if (numbers[i + 1] - numbers[i] != 1) { unStraight = false; break; } } if (unStraight) { if (sameColor) { up = 1; down = 16; } else { up = 1; down = 12; } } else { up = 0; down = 1; } } }
int main() { for (int i = 2; i < 10; i++) map.insert(make_pair((char) ('0' + i), i)); map.insert(make_pair('A', 1)); map.insert(make_pair('J', 11)); map.insert(make_pair('Q', 12)); map.insert(make_pair('K', 13)); string cards[4]; for (int i = 0; i < 4; i++) cin >> cards[i];
int up = 0, down = 0; probability(cards, up, down);
cout << up << "/" << down << endl;
return 0; }
|