[Problems] Description
digital Xiaoming 2,0,1,9 digit contain a very interest (not including the leading 0), 1 to
40, comprising such numbers 1,2,9,10 and 40 to 32, 39 a total of 28, and they are 574.
Will the 1 to n, all such numbers and how much?
[Input format
input line contains two integers n.
[] Output format
output line, comprising an integer, and represents a number satisfying the condition.
[Sample input]
40
[output] Sample
574
[Evaluation Example] Size and conventions used
for evaluation by 20% in Example, 1 ≤ n ≤ 10.
For evaluation by 50% in Example, 1 ≤ n ≤ 100.
For evaluation by 80% in Example, 1 ≤ n ≤ 1000.
For the evaluation all use cases, 1 ≤ n ≤ 10000.
As this problem can take to 10,000 N, the type used in large numbers, to prevent overflow.
import java.math.BigInteger; import java.util.Scanner; public class Main { public static boolean fun(int num) { S String = String.valueOf (NUM); // converts int String char [] = s.toCharArray Art (); // convert the string into an array for ( int I = 0; I <s.length ( ); I ++ ) { if(art[i]=='2' || art[i]=='0'|| art[i]=='1'||art[i]=='9') { return true; } } return false; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int a = scanner.nextInt(); BigInteger sum = new BigInteger("0"); for(int i=1;i<=a;i++) { IF (Fun (I)) // determines whether there 2,0,1,0 { NUM String = String.valueOf (i); // i is translated into strings a BigInteger One = new new a BigInteger (NUM); // the number of classes into large numbers SUM = sum.add (One); // to satisfy the condition accumulating the number of // System.out.println (SUM); } } System.out.print(sum); } }