fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. struct Card {
  8. int rank;
  9. char suit;
  10.  
  11. Card(int rank, char suit) {
  12. this->rank = rank;
  13. this->suit = suit;
  14. }
  15.  
  16. bool operator==(const Card &other) const {
  17. return suit == other.suit && rank == other.rank;
  18. }
  19.  
  20. string to_string() const {
  21. return ::to_string(rank) + string(1, suit);
  22. }
  23. };
  24.  
  25. int main() {
  26. const int HAND = 3;
  27. const int TABLE = 4;
  28.  
  29. vector<Card> hand;
  30. vector<Card> table;
  31.  
  32. for (int i = 0; i < HAND; i++) {
  33. int rank;
  34. char suit;
  35. scanf("%d%c", &rank, &suit);
  36. hand.emplace_back(rank, suit);
  37. }
  38.  
  39. for (int i = 0; i < TABLE; i++) {
  40. int rank;
  41. char suit;
  42. scanf("%d%c", &rank, &suit);
  43. table.emplace_back(rank, suit);
  44. }
  45.  
  46. bool comb_mat[16][TABLE] = {
  47. {false, false, false, false},
  48. {false, false, false, true},
  49. {false, false, true, false},
  50. {false, false, true, true},
  51. {false, true, false, false},
  52. {false, true, false, true},
  53. {false, true, true, false},
  54. {false, true, true, true},
  55.  
  56. {true, false, false, false},
  57. {true, false, false, true},
  58. {true, false, true, false},
  59. {true, false, true, true},
  60. {true, true, false, false},
  61. {true, true, false, true},
  62. {true, true, true, false},
  63. {true, true, true, true}
  64. };
  65.  
  66. vector<Card> best;
  67. Card settebello = Card(7, 'G');
  68.  
  69. int found_7s_out = 0;
  70. bool settebello_out = false;
  71. bool scopa_out = false;
  72.  
  73. for (int i = 0; i < HAND; i++) {
  74. for (int j = 0; j < 16; j++) {
  75. vector<Card> curr;
  76.  
  77. int found_7s_in = 0;
  78. bool settebello_in = false;
  79. bool scopa_in = false;
  80.  
  81. if (hand[i] == settebello) {
  82. settebello_in = true;
  83. }
  84.  
  85. if (j == 16 - 1) {
  86. scopa_in = true;
  87. }
  88.  
  89. int rank_sum = 0;
  90.  
  91. for (int k = 0; k < TABLE; k++) {
  92. Card card = table[k];
  93. if (comb_mat[j][k]) {
  94. curr.push_back(card);
  95. rank_sum += card.rank;
  96. if (card == settebello) {
  97. settebello_in = true;
  98. }
  99. if (card.rank == 7) {
  100. found_7s_in++;
  101. }
  102. }
  103. }
  104.  
  105. if (rank_sum == hand[i].rank) {
  106. if (!(settebello_out && !settebello_in)) {
  107. settebello_out = settebello_in;
  108. if (!(scopa_out && !scopa_in)) {
  109. scopa_out = scopa_in;
  110. if (found_7s_in > found_7s_out || (found_7s_in == found_7s_out && curr.size() > best.size())) {
  111. found_7s_out = found_7s_in;
  112. curr.push_back(hand[i]);
  113. best = curr;
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120.  
  121. for (const Card &card: best) {
  122. cout << card.to_string() << ' ';
  123. }
  124.  
  125. return 0;
  126. }
Success #stdin #stdout 0s 5304KB
stdin
6S 3B 8C
5S 2B 7G 1C


stdout
7G 1C 8C