洗澡

xiaoxiao2021-02-28  128

洗澡

时间限制: 1000 ms  |  内存限制: 65535 KB 难度: 1 描述

Mostrp是个爱干净的好少年。 有一次去澡堂洗澡时发现 澡堂的澡柜编号中没有出现过数字‘4’。 Mostrp 感到很好奇。可能是因为在澡堂老板眼里。数字‘4’是十分不吉利的。

现在Mostrp知道澡柜的最大的编号N,你能帮他算出澡堂一共有多少澡柜吗?

输入 有多组数据,每行输入一个N。 ( 1 <= N <= 50000 ) 输出 输出澡柜的个数,输出占一行。 样例输入 3 5 样例输出 3 4

import java.util.Scanner; public class Main { public static boolean judge(int number) { while (number != 0) { if (number % 10 == 4) { return false; } number /= 10; } return true; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int number = scanner.nextInt(); int count = 0; for (int i = 1; i <= number; i++) { if (judge(i)) { count++; } } System.out.println(count); } } }

转载请注明原文地址: https://www.6miu.com/read-31536.html

最新回复(0)