#141. 掷骰子求和与特殊规则
掷骰子求和与特殊规则
Dice Roll Sum
Background
In a casual board game, players roll two six-sided dice to determine their actions. To add more fun to the game, sometimes special rules are introduced.
Problem Description
Given the values of two 6-sided dice rolls, each in the range to . Return their sum. However, if noDoubles is true, and the two dice show the same value, increment one die to the next value, wrapping around to if its value was .
Input Format
Input is given from standard input in the following format.
die1 die2 noDoubles
die1 and die2 are the values of the two dice, and noDoubles is a boolean value (true or false).
Output Format
Output is printed to standard output in the following format.
sum
The adjusted sum of the two dice rolls.
Sample
2 3 true
5
3 3 true
7
3 3 false
6
Sample Explanation
- Sample 1: Dice values are and . Since they are not doubles, the
noDoublesrule does not apply. The sum is . - Sample 2: Both dice values are . Since they are doubles and
noDoublesis true, we increment one die's value from to . The sum is . - Sample 3: Both dice values are . Although they are doubles,
noDoublesis false, so the special rule is not applied. The sum is .
Constraints
noDoublesistrueorfalse.- Time limit: 1 second
- Memory limit: 1024 KB