Hide

Rolling The Dice

/problems/mines21.rollingthedice/file/statement/en/img-0001.jpg
Photo by Clément Bucco-Lechat. Retrieved from Wikimedia. Licensed under CC BY-SA 3.0

In Dungeons and Dragons, we use dice rolls very often to determine which actions succeed and which fail. There are many different dice with varying numbers of sides so we have a shorthand for representing different rolls. A single roll is written as “d#,” with the “#” representing the number of sides on the die. If you need to roll multiple dice of the same type, there will be a number before the “d”. For example, if you are required to roll 4d6, you would roll four six-sided dice and add the results together. There will also be a + after the notation, meaning that you add that number to the total results of the dice (not to each individual die rolled).

Higher numbers are better, and I want to make my character as powerful as possible, so I need to know what number I’ll get on average for different rolls. It’s relatively simple to do statistics on dice because every value has an equal chance of being rolled. If you average the minimum value and the maximum value of the roll, it will give you the value that you would get on average if you rolled it many times. For example, the roll 2d6+5 has a minimum value of $7$ if you roll two 1s and a maximum value of $17$ if you roll two $6$’s which gives an average of $12$ overall (for 2d6+5). Given the notation for a roll, find the average value of that roll.

Input

The input will be a single line in the form of “XdY+Z”. X, Y, and Z are all integers and will fall within the same range, $1 \le X, Y, Z \le 100$.

Output

Your program needs to output the average value that you would expect for the given roll values.

Sample Input 1 Sample Output 1
2d6+5
12
Sample Input 2 Sample Output 2
1d10+12
17.5
CPU Time limit 1 second
Memory limit 1024 MB
Author
Adam Sandstedt
Source [email protected] High School Programming Competition 2021
License Creative Commons License (cc by-sa)

Please log in to submit a solution to this problem

Log in