#C4110. Maximum Sum of Digits in a String
Maximum Sum of Digits in a String
Maximum Sum of Digits in a String
You are given a string s that consists entirely of digits. The task is to determine the maximum sum that can be obtained by inserting spaces between some of the digits to split the string into several numbers and then summing them up.
After analyzing the problem, you may notice that the optimal strategy is to consider the entire string as a single number without any splits. This is because splitting the string into smaller numbers only decreases the overall sum. Formally, if the string is represented as $$ s = d_0d_1\ldots d_{k-1}, $$ then the value of the number is given by $$ N = \sum_{i=0}^{k-1} d_i \times 10^{k-1-i}. $$ Thus, the maximum sum is simply N.
Your goal is to implement a function that reads the string from stdin
and prints the corresponding integer (i.e. the string interpreted as a number) to stdout
.
inputFormat
The input is given via stdin
and consists of a single line containing a non-negative integer in the form of a string. The string will only contain digits (0-9) and has no leading zeros unless it is exactly "0".
outputFormat
Output the maximum sum (which, based on the optimal strategy, is the number itself) to stdout
in a single line.
12345
12345