Connection Status:
Competition Arena > BlackjackWinner
SRM 241 · 2005-05-04 · by erinn · Math
Class Name: BlackjackWinner
Return Type: int
Method Name: winnings
Arg Types: (int, int, int, int, int)
Problem Statement

Problem Statement

In the game of blackjack, if the player scores higher than the dealer or the dealer goes over 21, and the player does not go over 21, then he wins his bet (in addition to keeping his original wager). If he scores 21 or less, and the same as the dealer, the hand is a push, and he keeps his bet. Otherwise, if he scores lower than the dealer, or goes over 21 (regardless of whether or not the dealer also does so), then he loses his bet.

A "blackjack" is a special kind of 21 point hand that beats all other hands. In such a case, the player wins 1.5 times his original bet. If both dealer and player have a blackjack, then the hand is a push. Note that if the dealer has a blackjack, and the player has a 21 (but does not have blackjack), then the dealer wins, and the player loses his wager.

You are given an int bet indicating the players wager, an int dealer indicating the dealer's score, and an int player indicating the player's score. Finally, you are given an int blackjack, which will be equal to 1 if the player has a blackjack, or 0 otherwise. Likewise, you are given the int dealerBlackjack.

You are to return the amount of money the player wins or loses on the hand. A win should return a positive number, either the player's bet, or 1.5 times his bet. A loss should be returned as a negative number. A push should return 0.

Constraints

  • bet will be between 2 and 100, inclusive, and will be even.
  • dealer will be between 17 and 26, inclusive.
  • dealerBlackjack will be 0 or 1.
  • dealerBlackjack may only be 1 if dealer is 21.
  • player will be between 4 and 30, inclusive.
  • blackjack will be 0 or 1.
  • blackjack may only be 1 if player is 21.
Examples
0)
10
20
0
21
0
Returns: 10

Here, the player beats the dealer (without blackjack), and wins his bet.

1)
26
21
1
21
0
Returns: -26

Here, the player loses... even though both dealer and player have 21, the dealer has a blackjack.

2)
100
25
0
21
1
Returns: 150

Here, the dealer went over, so as long as the player didn't go over, he's a winner. In fact, since he has a blackjack, he wins 1.5 times his original bet.

3)
78
22
0
23
0
Returns: -78

Even though the dealer went over, so did the player, so the player loses.

4)
80
24
0
24
0
Returns: -80

Submissions are judged against all 76 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class BlackjackWinner with a public method int winnings(int bet, int dealer, int dealerBlackjack, int player, int blackjack) · 76 test cases · 2 s / 256 MB per case

Submitting as anonymous