#C14028. Dice Rolling and Frequency Analysis
Dice Rolling and Frequency Analysis
Dice Rolling and Frequency Analysis
This problem involves two operations on a six-sided die. In roll mode, you are given a positive integer n and you must simulate rolling a die n times. However, instead of generating truly random numbers, use a deterministic sequence where the i-th roll is given by \((i \mod 6) + 1\). This guarantees consistency in the outputs.
\nIn freq mode, you are given a sequence of integers (each ideally between 1 and 6) representing die rolls. You need to compute and output the frequency of each outcome from 1 to 6. The frequency for outcome \(i\) is denoted by \(f_i\). If the input is invalid (i.e. an integer is not in the range from 1 to 6), output nothing.
inputFormat
The first token in the input will be a string indicating the operation mode. There are two modes:
\n- \n
- roll: The next line contains a single integer \(n\) (\(n\gt0\)). If \(n\) is not a positive integer, the program should output an empty line. \n
- freq: The next line contains a space-separated list of integers. If the list is empty, output frequencies as six zeros. If any integer is not between 1 and 6, output an empty line. \n
outputFormat
For roll mode: Output a single line with \(n\) space-separated integers corresponding to the simulated die rolls using the deterministic rule: the \(i\)-th roll is \((i \mod 6) + 1\).
\nFor freq mode: Output a single line with 6 space-separated integers where the \(i\)-th integer is the frequency of outcome \(i\) in the input list.
## sampleroll
10
1 2 3 4 5 6 1 2 3 4