int count = 1, maxCount = 0, elem = 0, maxElem = 0;
for (int i = 0; i < players; i++) {
for (int j = 1; j < 7; j++) {
if (arr[i][j] == arr[i][j - 1]) {
count++;
elem = arr[i][j - 1];
} else {
elem = 0;
count = 1;
}
if (count >= maxCount) {
maxCount = count;
maxElem = elem;
}
}
}
Not sure if it's 100% correct but this is how I managed to find the max element in this array and the number of its occurances.
This works only for one single (the max one) reoccuring element, though. What I need to do is to find all reoccuring elements. To be as precise as possible, I need to find whether there is either a two pair
or a full house
among those 7 j
s.
If someone doesn't know what those mean, a two pair is when there are two pairs of two equal numbers each. A full house is when there are two pairs, one of them consisting of two equal numbers, the other one of three equal numbers.
I need to find the biggest possible such pairs (both their values and numbers of occurance) amongst those 7 j
s.
I was thinking of using some sort of an array to store a pair if I find one but the problem is that I need to find such pairs for each and every i
. And initializing an array in a for loop
doesn't seem to be working out.
So how could I possibly find those pairs? Any advice or idea would be immensely appreciated!