题解 | #[NOIP2013]记数问题#

[NOIP2013]记数问题

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

试计算在区间1 到n 的所有整数中,数字x(0 ≤ x ≤ 9)共出现了多少次? 例如,在1到11 中,即在1、2、3、4、5、6、7、8、9、10、11 中,数字1 出现了4 次。

#include<stdio.h>
int main()
{
    int n, x;
    scanf("%d %d", &n, &x);
    int i;
    int count = 0;
    for (i = 1; i <= n; i++)
    {
        int m = i;
        while (m)
        {
            if (m % 10 == x)
                count++;
            m /= 10;
        }
    }
    printf("%d\n", count);
}
全部评论

相关推荐

昨天 22:21
门头沟学院 Java
点赞 评论 收藏
分享
做黑夜里的那道光:两年电赛完赛没必要写,纯扣分
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
45
1
分享

创作者周榜

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