How Many 0's

How Many Os?

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

算一算每一位对应会有多少个0,然后两个数相减即可

#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define int long long
int cul(int x)
{
    if (x < 0) return 0;
    int res = 1, last = 0, base = 1;
    while (x) {
        int tmp = x % 10;
        x /= 10;
        if (tmp) res += x * base;
        else res += (x - 1) * base + 1 + last;
        last += tmp * base;
        base *= 10;
    }
    return res;
}
signed main() 
{
    int n, m;
    while (scanf("%lld%lld", &n, &m) != EOF)
    {
        if (n == -1 && m == -1) break;
        printf("%lld\n", cul(m) - cul(n - 1));
    }
}
全部评论

相关推荐

收到了小米的实习offer,犹豫是否要去。。。
认真搞学习:雷总还当过首富呢,公司不算大厂算独角兽吗
点赞 评论 收藏
分享
深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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