TopCoder problem "BlackjackWinner" used in SRM 241 (Division II Level One)



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.

 

Definition

    
Class:BlackjackWinner
Method:winnings
Parameters:int, int, int, int, int
Returns:int
Method signature:int winnings(int bet, int dealer, int dealerBlackjack, int player, int blackjack)
(be sure your method is public)
    
 

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.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4500

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7216&pm=4500

Writer:

timmac

Testers:

PabloGilberto , lbackstrom , brett1479

Problem categories:

Math