日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces 1060b Maximum Sum of Digits(思维题)

發(fā)布時間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces 1060b Maximum Sum of Digits(思维题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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。思路就是這個。
代碼如下:

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define ll long long using namespace std;ll n; ll temp1; ll temp2;int main() {while(scanf("%I64d",&n)!=EOF){int sum1=0;int sum2=0;temp1=1;while(1){temp1*=10;if(temp1*10>=n)break;}temp1--;temp2=n-temp1;while(temp1){sum1+=temp1%10;temp1/=10;}while(temp2){sum2+=temp2%10;temp2/=10;}cout<<sum1+sum2<<endl;}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的codeforces 1060b Maximum Sum of Digits(思维题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。