https://codeforces.com/contest/1060/problem/B
题意:给你一个数C ,你要找到两个数A、B,使得A+B=C并且A的每个位的数的和最大,求最大的和是多少
题解:肯定是9最大了,那么我们就要找最多有多少个9
1.先找离这个数最大的10的幂次倍是多少,比如101最大的是100
2.将离他最大的数减1即可得到最多的9的个数
3.将这个数减去已经数过的9的那个数,得到另一个数,分解即可
代码如下:
#include <map> #include <set> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <bitset> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #define PI acos(-1) #define eps 1e-8 #define fuck(x) cout<<#x<<" = "<<x<<endl; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w+",stdout); //#pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 1e5+5; const int INF = 0x3f3f3f3f; const int MOD = 1e9+7; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;} LL lcm(LL a,LL b){return a/gcd(a,b)*b;} LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;} double dpow(double a,LL b){double ans=1.0;while(b){if(b%2)ans=ans*a;a=a*a;b/=2;}return ans;} int main(){ #ifndef ONLINE_JUDGE FIN #endif LL n; cin>>n; LL m=n; LL cnt=0; LL tmp=1; while(m>9){ tmp*=10; cnt++; m/=10; } tmp--; LL t1=tmp; LL t2=n-t1; LL ans=0; while(t1){ ans+=t1%10; t1/=10; } while(t2){ ans+=t2%10; t2/=10; } cout<<ans<<endl; }