题目描述
试计算在区间? 11? 到? nn 的所有整数中, 数字 x(0 ≤ x ≤ 9)x(0≤x≤9) 共出现了多少次? 例如, 在? 11 到 1111 中, 即在? 1,2,3,4,5,6,7,8,9,10,111,2,3,4,5,6,7,8,9,10,11? 中, 数字? 11? 出现了? 44? 次.
输入输出格式
输入格式:
22 个整数 n,xn,x, 之间用一个空格隔开.
输出格式:
11 个整数, 表示 xx 出现的次数.
- import java.util.Scanner;
- public class Main {
- public void Breakup(int arr[], int n) {
- while(n!=0) {
- arr[n%10]++;// 个位取值
- n=n/10;// 十位变个位
- }
- }
- //public void Breakup(int arr[], int n) {思路正确 细节出错 这也是我发博客纪念这道题的原因
- // String str = String.valueOf(n);
- // for (int i = 0; i < str.length(); i++) {
- // char c = str.charAt(i);
- // String str2 = String.valueOf(c);
- // int x = Integer.parseInt(str2);
- // arr[x]++;
- // }
- //}
- public static void main(String[] args) {// 测试用例
- Scanner sc = new Scanner(System.in);
- Main m = new Main();
- int x = sc.nextInt();
- int i = sc.nextInt();
- int arr[] = new int[10];
- for (int temp = 0; temp <= x; temp++) {
- m.Breakup(arr, temp);
- }
- System.out.println(arr[i]);
- }
- }
级数问题
来源: http://www.bubuko.com/infodetail-3117194.html