codeforces 1060b Maximum Sum of Digits(思维题)
You are given a positive integer
n
Let
S(x) be sum of digits in base 10 representation of
x, for example,
S
(
123
S(123)=1+2+3=6,
S(0)=0.
Your task is to find two integers
a,b, such that
0≤a,b≤n,
a+b=n and S(a)+S(b) is the largest possible among all such pairs.
Input
The only line of input contains an integer
n(1≤n≤1012).
Output
Print largest
S(a)+S(b) among all pairs of integers a,b, such that 0≤a,b≤n and a+b=n.
Examples
inputCopy
35
outputCopy
17
inputCopy
10000000000
outputCopy
91
Note
In the first example, you can choose, for example, b=18, so that S(17)+S(18)=1+7+1+8=17. It can be shown that it is impossible to get a larger answer.
In the second test example, you can choose, for example,
a=5000000001 and b=4999999999, witS(5000000001)+S(4999999999)=91. It can be shown that it is impossible to get a larger answer.
要求求一個數(shù)n的兩個可以加和為n的數(shù)的各個位上數(shù)字加和的最大值。。
像這個題,我們要做的就是多出9。。先求不大于n的10的冪次數(shù),然后再減一。例如:101,不大于它的數(shù)是100,100-1=99。這樣就有了兩個9。思路就是這個。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的codeforces 1060b Maximum Sum of Digits(思维题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces 1060a(思维
- 下一篇: B - Average Numbers