#include #include #include #include #include using namespace std; class pair2 { public: string first; int second; pair2(string aa, int bb) : first(aa), second(bb) {} }; pair2 make_pair2(string aa, int bb) { return pair2(aa, bb); } static string arr[5][2]; // num card static int number = 0; static int total = 0; static int last = 0; static bool sevenCalled = false, eightCalled =false; static bool nineChanged = true, nineCalled = false; static bool tenChanged = true, tenCalled = false;; static bool elevenChanged = true, elevenCalled = false; static map valToRank; static int noSuits[4]; bool devet(bool last = false ) { if (!(noSuits[0] >= 3)) { return false; } nineCalled = true; int totalO = total; total++; bool swapped[5] = {0,0,0,0,0}; for (int i = 0; i < 4 ; i ++) { for (int j = 0; j < 5; j++) { if (!swapped[j]) { if (valToRank[arr[j][0]] == 6) { arr[j][0] = "9"; //total += 3; swapped[j] = true; }else if (valToRank[arr[j][0]] == 9) { arr[j][0] = "6"; //total -= 3; swapped[j] = true; } else if (valToRank[arr[j][0]] == 2) { arr[j][0] = "5"; //total += 3; swapped[j] = true; }else if (valToRank[arr[j][0]] == 5) { arr[j][0] = "2"; //total -= 3; swapped[j] = true; } } } } if (last) { last = 9; number++; } if (total == totalO) { nineChanged = false; } return total != totalO; } bool osm(bool last = false) { if (total >= 0) return false; eightCalled = true; total *= -1; if (last) { last = 8; number++; } return true; } bool sedm(bool last = false) { if (total < 0) return false; sevenCalled = true; int min = 200000; for (int i = 0; i < 5; i++ ) { if (valToRank[arr[i][0]] < min) { min = valToRank[arr[i][0]]; } } total += min; if (last) { last = 7; number++; } return true; } void deset(bool last = false) { int totalO = total; vector vec; for (int i = 0; i < 5; i++) { vec.emplace_back(make_pair2(arr[i][0], valToRank[arr[i][1]])); if (vec[i].second == 10) { if (vec[i].first == "J") { vec[i].second = 11; } else if (vec[i].first == "Q") { vec[i].second = 12; }else if (vec[i].first == "K") { vec[i].second = 13; }else if (vec[i].first == "A") { vec[i].second = 14; } } } sort(vec.begin(), vec.end(), [] (const pair2 a, const pair2 b) { return a.second < b.second; }); bool f = true; for (int i = 0; i < 4; i++) { if (vec[i].second+1 != vec[i+1].second) { f = false; break; } } if (f) { tenCalled = true; int as = 0; for (int i = 0; i < 5; i++) { if (arr[i][0] == "A") as++; } total += as*5; if (last) { last = 10; number++; } } tenChanged = total != totalO; } void jedenact(bool last = false) { int totalO = total; if (number >= 8) { elevenCalled = true; int totalc =total; int res = 0; while (totalc > 0) { if (totalc%2 == 1) total++; totalc /= 2; } if (last) { number++; last = 11; } } elevenChanged = total != totalO; } int main(int argc, char** argv) { valToRank["2"] = 2; valToRank["3"] = 3; valToRank["4"]= 4; valToRank["5"]= 5; valToRank["6"]= 6; valToRank["7"]= 7; valToRank["8"]= 8; valToRank["9"]= 9; valToRank["10"]= 10; // warn valToRank["J"]= 10; valToRank["Q"]= 10; valToRank["K"]= 10; valToRank["A"]= 10; for (int i = 0; i < 5; i++) { string k; cin >> k; if (k.size() != 3) { arr[i][0] = k[0]; arr[i][1] = k[1]; } else { arr[i][0] = "10"; arr[i][1] = k[2]; } } //---------- for (int i =0 ; i < 5; i ++) { total += valToRank[arr[i][0]]; } last = 1; number++; //cout << total << endl; total++; int J = 0; for (int i = 0; i < 5; i++) { if (arr[i][0] == "J") J++; } total += J * valToRank[arr[0][0]]; //cout << total << endl; /*-----*/ noSuits[0] = 0; noSuits[1] = 0; noSuits[2] = 0; noSuits[3] = 0; map su; su["D"] = 0; su["H"] = 1; su["C"] = 2; su["S"] = 3; for (int i = 0; i < 5; i++ ) { noSuits[su[arr[i][1]]]++; } bool s = false; for (int i = 0; i < 4; i++ ) { if (noSuits[i] >= 2) { s = true; break; } } if (s) { last = 2; total *= 2; number++; } //cout << total << endl; /* -- */ s = true; for (int i = 0; i < 4; i++ ) { if (noSuits[i] == 0) s = false; } if (s) { last = 3; total *= 2; number++; } int diffCS, diffDH; diffCS = noSuits[2] + noSuits[3]; diffDH = noSuits[0] + noSuits[1]; if (diffCS != diffDH) { total += abs(diffCS - diffDH); last = 4; number++; } //cout << total << endl;/* /* * skip 5 */ int numberOfSeven = 0; for (int i = 0; i < 5; i++ ) { if (valToRank[arr[i][0]] == 7) numberOfSeven++; } if (numberOfSeven == 4) { total -= 11*11; last = 6; number++; } //cout << total << endl;/*****/ sedm(true); //cout << total << endl; /*/*/ osm(true); //cout << total << endl; /***/ devet(true); //cout << total << endl; deset (true); //cout << total << endl; jedenact(true); //cout << total << endl; for (int i =0 ; i < 5; i++) { if (valToRank[arr[i][0]] == 2) { if (elevenCalled && elevenChanged) { jedenact(); } else if (tenCalled && tenChanged) { deset(); } else if (nineCalled && nineChanged) { devet(); }else if (eightCalled) { osm(); } else if (sevenCalled) { sedm(); } break; } } //cout << total << endl; for (int i =0 ; i < 5; i++) { if (valToRank[arr[i][0]] == 2) { // int totalC = total; // int lastSuper = 2; // int arr1[10000]; // for (int j = 0; j < 10000; j++) { // arr1[j] = 0; // } // while (totalC > 0) { // if (totalC%lastSuper == 0) { // totalC/2; // arr1[lastSuper]++; // } else { // lastSuper++; // } // } total*= 2; break; } } cout << total << endl; return 0; }