Problem Statement
PROBLEM STATEMENT
In the game of craps a player rolls a pair of dice. A die is a six-sided cube
with a value on each side. That value can be one of 1, 2, 3, 4, 5, 6. When
the player rolls a pair of dice, the two sum of the two values on the top side
of each of the die determine the "combined score" of the roll.
The rules of this game are as follows:
*On the player's first roll of a game, if a player roles a combined score of 2,
3, or 12, they lose and the game is over.
*On the player's first roll of a game, if a player roles a combined score of 7,
or 11, they win and the game is over.
*On the player's first roll of a game, if a player roles a 4, 5, 6, 8, 9, or
10, this score is known as "the point", and the game is not yet over. The
player continues to roll until he gets a combined score of either 7 or "the
point". If the player rolls a 7, the player loses and the game is over. If
the player rolls "the point", they win and the game is over.
Create a class Craps that contains the method difference, which takes in the
parameter rolls, and returns the difference between wins and losses (wins -
losses) seen by the end of the rolls.
DEFINITION
Class: Craps
Method: difference
Parameters: String[]
Returns: int
Method signature (be sure your method is public): int difference(String[] rolls);
NOTES:
- The input may be such that the last game has not yet ended. If this is the
case, the last game should be ignored.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
- rolls will contain between 1 and 50 elements (inclusive)
- each element of rolls will be formatted "x,y", where x and y are the values
on the pair of dice (double quote are just for clarity).
- x is a number between 1 and 6 inclusive.
- y is a number between 1 and 6 inclusive.
EXAMPLES
1) rolls = {"2,4","1,1","3,4","2,4"} Method returns -1
"2,4" sets the point to 6
"1,1" does not win nor lose because it is not "the point" nor 7
"3,4" causes a loss
"2,4" sets the point to 6, but the game does not finish.
wins (0) - loses(1) = -1
Method returns -1
2)
rolls = {"6,1","1,1","5,6","5,5","2,3","6,4","2,3","1,4"}
"6,1" combined score is 7, so the player wins.
"1,1" combined score is 2, so the player loses.
"5,6" combined score is 11, so the player wins.
"5,5" combined score is 10, this sets "the point" to 10.
"2,3" combined score is 5 which is neither 7 nor "the point" so the player
keeps going.
"6,4" combined score is 10, which is "the point", so the player wins.
"2,3" combined score is 5, this sets "the point" to 5.
"1,4" combined score is 5, which is "the point", so the player wins.
wins (4) - loses(1) = 3
Method returns 3
3) rolls = {"1,1"} Method returns -1
4) rolls = {"1,1","3,4"} Method returns 0
Definition
- Class:
- Craps
- Method:
- difference
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int difference(String[] param0)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.