题解 | #[NOIP2013]记数问题#
[NOIP2013]记数问题
https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char x = sc.next().charAt(0);//直接将X输入为char方便后面比较 int count = 0; for (int i = 1; i <= n; i++) {//外循环:从1——n String a = Integer.toString(i);//转字符串,方便逐位比较 for (int j = 0; j < a.length(); j++ ) {//内循环:一个数的每一位 if(a.charAt(j)==x){ count++; }; } } System.out.print(count); } }
#做项目#