#P17355. [ECNA 2024] Average Substring Value
[ECNA 2024] Average Substring Value
Problem Description
Let be a nonempty string consisting entirely of digits (0--9). If the length of is number the digits from left to right, and for let denote the substring consisting of the digits from to inclusive. (It follows that we are only considering nonempty substrings.) Assign a value to each substring that is simply equal to the largest digit in the substring. What is the average value of the substrings ?
Note that two different substrings may be identical (as strings), but for the purposes of this problem they are treated as distinct. For example, if then are distinct substrings (both with
Input Format
The input is a single nonempty string, of digits. The length of is at most
Output Format
Output a line containing the average value of the substrings of If the average is an integer, print the integer. If the average is a proper fraction, i.e., is equal to where and are positive integers and , print this fraction in lowest terms, with a '/' symbol separating the numerator and denominator. If the average is greater and does not simplify to an integer, print the whole part followed by the proper fractional part, separated by a space, with the proper fractional part in lowest terms and formatted as described in the previous sentence.
123
2 1/3
4084
6
1010
4/5
00000
0