Loading

题解 CF1060B 【Maximum Sum of Digits】

先讲一下思路

首先输入一个数s;

然后要把S拆为A+B;

那么,A的各个数位要尽可能大;

一:找出S的位数CNT,A加上CNT-1位9;

比如S=2233213123的话,A一开始就等于

       999999999

二:A的第一位为S第一位数字-1

此时A就变成了1999999999

三:算出B=S-A,拆位,输出ans

(此时ans=109)

四:return 0;

然后你又AC了一道蓝题

最后

上代码

#include<iostream>
using namespace std;
long long a=0,b,s,hk416,pow[15];
int fuze(long long a)

{
	int cnt=0;
	while(a)
	{
		cnt+=a%10;
		a/=10;
		}
	cnt+=a;
	return cnt;
}
int main()

{
	pow[0]=1;
	for(int i=1;i<=14;i++)
		pow[i]=10*pow[i-1];
	cin>>s;
	hk416=s;
	int cnt=0;
	while(s/10)
	{
		a=a*10+9;
		s/=10;
		cnt++;
		
		}

	a+=(s-1)*pow[cnt];
	b=hk416-a;

	
	cout<<fuze(a)+fuze(b)<<endl;
	return 0;
}
posted @ 2019-03-16 19:16  AntiO2  阅读(81)  评论(0编辑  收藏  举报