题解 | #数位五五#

数位五五

https://ac.nowcoder.com/acm/problem/22168

代码太长可以用函数来实现,把判断是不是倍数的部分单独放出来

using namespace std;
#define int long long
#define endl '\n'
bool isbeishu(int n){
    int s=0;
    while(n>0){
    s+=n%10;
    n=n/10;
    }
    if(s%5==0)return true;
    else return false;
}
signed main(){
    std::ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    int a,b;cin>>a>>b;
    int sum=0;
    for(int i=a;i<=b;i++){
        if(isbeishu(i))sum++;
    }
    cout<<sum<<endl;
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务