RPG
SRM 171 · 2003-11-12 · by Running Wild
Problem Statement
Constraints
- dice will contain between 1 and 5 elements, inclusive.
- Each element of dice will be formatted "ndx" (quotes for clarity only), where 'n' is an integer between 1 and 10, inclusive, 'd' is the character 'd', and 'x' is an integer between 2 and 20, inclusive. Neither 'n' nor 'd' will have leading zeros.
{"3d6"}
Returns: { 3, 18, 10 }
Standard roll for creating characters stats in a popular RPG. The minimum value is when three 1's are rolled, the maximum value is when all 6's are rolled, and the average value is given by 3*(6+1)/2, which rounds down to 10.
{"3d4","1d6"}
Returns: { 4, 18, 11 }
Be careful not to round the value of intermediate results. The average roll of "3d4" is 3*(1+4)/2=7.5, and the average roll of "1d6" is 1*(1+6)/2=3.5. The average of them both is 11, but rounding before adding them together will yield 10, which is incorrect.
{"6d5","10d10","10d20"}
Returns: { 26, 330, 178 }
{"1d2","2d2","4d2","6d2","8d2"}
Returns: { 21, 42, 31 }
{"5d2"}
Returns: { 5, 10, 7 }
Submissions are judged against all 35 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RPG with a public method vector<int> dieRolls(vector<string> dice) · 35 test cases · 2 s / 256 MB per case