Created
April 8, 2017 17:34
http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=15856 這題就是算有幾個8注意當800多時是例外每增加一個數字就加一
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
int n = scn.nextInt(), tot = n / 100 * 20; | |
Boolean b = true; | |
if (n / 100 == 8) { | |
tot += n % 100 + 1; | |
} | |
n %= 100; | |
tot += n / 10; | |
if (n > 88 && n / 10 != 8) | |
b = false; | |
if (n >= 80 && n < 90) | |
tot += n - 79; | |
else if (n >= 90) | |
tot += 10; | |
if (n >= 98) | |
tot++; | |
n %= 10; | |
if (n >= 8 && n <= 9 && b) | |
tot++; | |
System.out.println(tot); | |
} | |
/*題目:C_MM261-易 數字的出現次數 | |
作者:1010 | |
時間:西元 2017 年 4 月*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment