题解 | #挑7#

挑7

http://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for (int i = 1; i <= n; i++) {
                if (i % 7 == 0) {
                    set.add(i);
                }
            }
            for (int i = 1; i <= n; i++) {
                String s = String.valueOf(i);
                for (int j = 0; j < s.length(); j++) {
                    if(s.charAt(j) == '7'){
                        set.add(i);
                    }
                }
            }
            System.out.println(set.size());
        }
    }

}
全部评论

相关推荐

2025-12-17 17:15
华东师范大学 运营
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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