题解 | 记数问题

记数问题

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

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),x = in.nextInt();
        int cnt = 0;
        for(int i=1;i<=n;i++){
            int j = i;
            while(true){
                if(j==0)break;
                if(j%10==x)cnt++;
                j/=10;
            }
        }
        System.out.println(cnt);
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:04
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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