题解 | #[NOIP2013]记数问题#
[NOIP2013]记数问题
http://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
int z = str.indexOf(" ");
String a = str.substring(0, z);
String b = str.substring(z + 1, str.length());
int n = Integer.parseInt(a);
int x = Integer.parseInt(b);
int count = 0;
for(int i = 1; i <= n; i++) {
if(i == x) {
count++;
} else {
if(i / 10 != 0) {
int q = 0;
int w = i;
while(w != 0) {
q = w % 10;
if(q == x) {
count++;
}
w /= 10;
}
}
}
}
System.out.println(count);
}
}
Java基础练习题 文章被收录于专栏
都是一些基础的语法题目,每天可以刷几道。