先打出0~8位數,分別可以被整十/百/千/萬...整除時 , 各個數字出現了幾次的表
先把每要查詢的數字的每一位在表裡查詢得到一個結果
但是這樣是不全面的,考慮這樣的情況: 例如2345這樣的數 234* 這種情況下 4出現了5次 23**這種情況下3出現了45次 2***中2出現了345次等.....從後往前掃一遍即可
其中0的情況比較特殊,簡單的掃一遍會漏掉很多可能 比如 5050時: 500*的情況下,第2個0就沒有考慮到,所以還要進行一次補0的操作.
排除首位從前往後掃,遇到每一個不為0的數就考慮將這位變成0,如果這個數後面還有1個數就有9中可能,後面有2個數就有108種可能(9+99) 有3個數就有(9+99+999)種可能...依次類推.....
結果加到一起就是答案
The Counting Problem
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 421 Accepted Submission(s): 169
Problem Description
Given two integers a and b, we write the numbers between a and b, inclusive, in a list. Your task is to calculate the number of occurrences of each digit. For example, if a = 1024 and b = 1032, the list will be
1024 1025 1026 1027 1028 1029 1030 1031 1032
there are ten 0's in the list, ten 1's, seven 2's, three 3's, and etc.
Input
The input consists of up to 500 lines. Each line contains two numbers a and b where 0 < a, b < 100000000. The input is terminated by a line `0 0', which is not considered as part of the input.
Output
For each pair of input, output a line containing ten numbers separated by single spaces. The first number is the number of occurrences of the digit 0, the second is the number of occurrences of the digit 1, etc.
Sample Input
1 10
44 497
346 542
1199 1748
1496 1403
1004 503
1714 190
1317 854
1976 494
1001 1960
0 0
Sample Output
1 2 1 1 1 1 1 1 1 1
85 185 185 185 190 96 96 96 95 93
40 40 40 93 136 82 40 40 40 40
115 666 215 215 214 205 205 154 105 106
16 113 19 20 114 20 20 19 19 16
107 105 100 101 101 197 200 200 200 200
413 1133 503 503 503 502 502 417 402 412
196 512 186 104 87 93 97 97 142 196
398 1375 398 398 405 499 499 495 488 471
294 1256 296 296 296 296 287 286 286 247
Source
2004 Asia Regional Shanghai
/* ***********************************************
Author :CKboss
Created Time :2015年02月01日 星期日 13時58分50秒
File Name :HDOJ1663_3.cpp
************************************************ */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include