题解 | 记数问题

记数问题

https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732

#include <stdio.h>

int main() {
    int n, x, temp;
    int i_cnt, x_total_cnt, i;

    scanf("%d %d", &n, &x);

    x_total_cnt = 0;
    for(i = 1; i <= n; i++) {
        i_cnt = 0;
        temp = i;
        while(temp) {
            if(temp % 10 == x) {
                i_cnt++;
            }
            temp = temp / 10;
        }
        x_total_cnt += i_cnt;
    }
        // 64 位输出请用 printf("%lld") to 
    
    printf("%d\n", x_total_cnt);
    
    return 0;
}

全部评论

相关推荐

Ncsbbss:又想干活又想要工资,怎么什么好事都让你占了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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