## Algorithm

Problem Name: 2 AD-HOC - beecrowd | 1337

# King’s Poker

By Ricardo Anido Brazil

Timelimit: 1

Poker is one of the most widely played card games, and King's Poker is one of its variations. The game is played with a normal deck of 52 cards. Each card has one of 4 suits and one of 13 ranks. However, in King's Poker card suits are not relevant, while ranks are Ace (rank 1), 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack (rank 11), Queen (rank 12) and King (rank 13). The name of the game comes from the fact that in King's Poker, the King is the highest ranked card. But this is not the only difference between regular Poker and King's Poker. Players of King's Poker are dealt a hand of just three cards. There are three types of hands:

• A set, made of three cards of the same rank.
• A pair, which contains two cards of the same rank, with the other card unmatched.
• A no-pair, where no two cards have the same rank.

Hands are ranked using the following rules:

• Any set defeats any pair and any no-pair.
• Any pair defeats any no-pair.
• A set formed with higher ranked cards defeats any set formed with lower ranked cards.
• If the matched cards of two pairs have different ranks, then the pair with the higher ranked matched cards defeats the pair with the lower ranked matched cards.
• If the matched cards of two pairs have the same rank, then the unmatched card of both hands are compared; the pair with the higher ranked unmatched card defeats the pair with the lower ranked unmatched card, unless both unmatched cards have the same rank, in which case there is a tie.

A new software house wants to offer King's Poker games in its on-line playing site, and needs a piece of software that, given a hand of King's Poker, determines the set or pair with the lowest rank that beats the given hand. Can you code it?

## Input

Each test case is described using a single line. The line contains three integers A, B, and C representing the ranks of the cards dealt in a hand (1 ≤ A, B, C ≤ 13).

The last test case is followed by a line containing three zeros.

## Output

For each test case output a single line. If there exists a set or a pair that beats the given hand, write the lowest ranked such a hand. The beating hand must be written by specifying the ranks of their cards, in non-decreasing order. If no set or pair beats the given hand, write the character '*' (asterisk).

 Sample Input Sample Output 1 1 1 1 1 12 1 1 13 1 13 1 10 13 10 1 2 2 13 13 13 13 12 13 12 12 12 3 1 4 1 5 9 0 0 0 2 2 2 1 1 13 1 2 2 1 2 2 1 11 11 2 2 3 * 1 1 1 13 13 13 1 1 2 1 1 2

## Code Examples

### #1 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
ios::sync_with_stdio(false);
int a, b, c;
vector<int> king(3);
for (cin >> king[0] >> king[1] >> king[2]; king[0] != 0 && king[1] != 0 && king[2] != 0; cin >> king[0] >> king[1] >> king[2]) {
bool p = false, s = false;
if (king[0] == king[1]) {
if (king[1] == king[2])
p = s = true;
else
p = true;
} else {
if (king[1] == king[2])
p = true;
else if (king[0] == king[2])
p = true;
}
sort(king.begin(), king.end());
if (!p && !s)
cout << "1 1 2\n";
else {
if (!p && s || p && !s) {
if (king[1] > king[0] && king[1]  < = 13 && king[0] < 12) {
if (king[0] + 1 != king[1])
king[0]++;
else
king[0] += 2;
sort(king.begin(), king.end());
cout << king[0] << " " << king[1] << " " << king[2] << "\n";
} else {
if (king[1] > king[0] && king[0] == 12)
cout << "1 1 1\n";
else {
if (king[2] > king[1] && king[2]  <  13)
cout << king[0] << " " << king[1] << " " << ++king[2] << "\n";
else if (king[2] > king[1] && king[2] == 13)
cout << "1 " << ++king[0] << " " << ++king[1] << "\n";
}
}
} else {
if (p && s && king[0]  <  13)
cout << ++king[0] << " " << ++king[1] << " " << ++king[2] << "\n";
else
cout << "*\n";
}
}
}
return 0;
}
``````
Copy The Code &

Input

cmd
1 1 1
1 1 12
1 1 13
1 13 1
10 13 10
1 2 2
13 13 13
13 12 13
12 12 12
3 1 4
1 5 9
0 0 0

Output

cmd
2 2 2
1 1 13
1 2 2
1 2 2
1 11 11
2 2 3
*
1 1 1
13 13 13
1 1 2
1 1 2