Problem O
Who Wins
You are at the casino playing a simplified game of Blackjack. The dealer has revealed their final
hand. Your task is to determine who wins the round.
Blackjack is played with standard playing cards. Each card has a rank: 2-10, J, Q, K, or A. The value of each card is:
-
Number cards 2-10 are worth their numeric value.
-
Face cards J, Q, K are worth $10$.
-
An A (Ace) is worth either $1$ or $11$, whichever is more favourable without causing the hand to exceed $21$.
The value of a hand is the maximum possible total not
exceeding $21$. If all
possible totals exceed $21$, the hand is said to be
bust.
The outcome of the round is determined as follows:
-
If both player and dealer bust, the result is a Push.
-
If only the player busts, the Dealer wins.
-
If only the dealer busts, the Player wins.
-
Otherwise, the hand with the higher total wins.
-
If both totals are equal, the result is a Push.
You are given both hands after all cards have been drawn. Determine the result.
Input
The first line contains an integer $d$ ($1 \le d \le 3$), the number of cards in the dealer’s hand. The second line contains $d$ strings describing the dealer’s cards. The third line contains an integer $p$ ($1 \le p \le 3$), the number of cards in the player’s hand. The fourth line contains $p$ strings describing the player’s cards.
Each card is one of: {2,3,4,5,6,7,8,9,10,J,Q,K,A}.
Output
Output exactly one of the following strings:
-
Player if the player wins,
-
Dealer if the dealer wins,
-
Push if both player and dealer bust or both totals are equal.
| Sample Input 1 | Sample Output 1 |
|---|---|
3 J Q K 2 10 9 |
Player |
| Sample Input 2 | Sample Output 2 |
|---|---|
2 10 9 3 J Q K |
Dealer |
| Sample Input 3 | Sample Output 3 |
|---|---|
3 8 9 10 3 J Q K |
Push |
| Sample Input 4 | Sample Output 4 |
|---|---|
3 5 6 7 3 5 6 7 |
Push |
| Sample Input 5 | Sample Output 5 |
|---|---|
3 10 A 9 3 5 6 7 |
Dealer |
| Sample Input 6 | Sample Output 6 |
|---|---|
3 5 6 7 3 10 A 9 |
Player |
| Sample Input 7 | Sample Output 7 |
|---|---|
3 A A A 2 A A |
Dealer |
