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
|
#include <iostream>
using std::cout;
bool checkHand(int hand[5])
{
int counts[10]{};
// Get the count of each number in the hand
for (unsigned i=0; i<5; ++i) {
++counts[hand[i]];
}
// Get the maximum frequency of a number in the hand
unsigned maxIdx=2;
for (unsigned i=2; i<=9; ++i) {
if (counts[i] > counts[maxIdx]) {
maxIdx = i;
}
}
cout << "There are " << counts[maxIdx] << " cards with value " << maxIdx
<< '\n';
return (counts[maxIdx] == 2 || counts[maxIdx] == 3);
}
int
main()
{
int hands[5][5] = { {2,2,3,4,5},
{2,3,2,3,4},
{2,2,2,3,3},
{2,2,2,3,4},
{2,2,2,2,3}
};
for (unsigned i=0; i<5; ++i) {
cout << checkHand(hands[i]) << '\n';
}
return 0;
}
|