0
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 js.

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 js.

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!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3213110
  • 199
  • 4
  • 14

1 Answers1

1

To solve your problem and easier way to find 2 pairs or any thing else count your arr[][] into one dimension: arr[13] (I guess it's cards, 2 - Ace) Then you can pass this array to check what ever you want like count pairs or full house and to know their numbers

Edit: Now I paid attention about the first dimension is the player, so you can do the same with arr[players][13]

Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
  • So what you're proposing is to make an array for the cards themselves, right? What would I store in it, though? And where do I initialize it? I was thinking in the first `for` loop but wouldn't that be problematic? – user3213110 Apr 01 '15 at 20:57
  • 1
    Yes, each cell/index counter the number of: cardVal - 2 (arr[0]=counter of cards number 2, arr[1]=counter of cards number 3 and so on..) it should replace the second loop – Roy Shmuli Apr 01 '15 at 21:03