标签:string 难度 tip return 数据 题目 std cst int
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 100 + 10;
int cnt =0;
int main(){
int n; scanf("%d", &n);
for(int i=1;i<=n;i++) {
char ch;
cin>>ch;
if(ch == ‘8‘) cnt++;
}
int ans=0;
while(n){
if(cnt&&n>=11) cnt--,n-=11,ans++;
else break;
}
printf("%d",ans);
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long cal(long long a){
long long ans=0;
while(a){
long long dig=a%10;
ans+=dig;
a/=10;
}
return ans;
}
long long fpow(long long a,long long b){
long long ans=1;
for(;b;b>>=1){
if(b&1) ans*=a;
a*=a;
}
return ans;
}
int main(){
long long n; scanf("%I64d", &n);
long long ans;
long long a ;
if(n<10) a= n;
else {
a = 0;long long cnt=0;
while(a<=n) a=a*10+9,cnt++;
if(a>n) a/=10,cnt--;
long long top;long long x=n;
while(x){
if(x/10>0)top=x/10;
x/=10;
}
top--;
long long pw=fpow(10,cnt);
a=(long long)top*pw+a;
}
long long b ;
if(n<10) b=0;
else {
b = n-a;
}
ans = cal(a) + cal(b);
printf("%I64d",ans);
return 0;
}
Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2)
标签:string 难度 tip return 数据 题目 std cst int
原文地址:https://www.cnblogs.com/Loi-Brilliant/p/9822975.html