一、内容

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

二、思路

  • 首先我们求n = abcdefg,我们求x出现的次数。
  • 当x > 0的情况:
    (1) x取d这个位置时,000 ~ abc-1,x,000 ~ 999, 那么种数为 abc * 1000
    (2) abc,x,后面分成3种情况
         a. 当d < x 时,种数为0
         b.当 d = x 时,种数为000 ~ efg, efg+1种
         c. 当d > x 时,种数为000 ~ 999, 1000种
  • 当x = 0的情况:
    (1) x取d这个位置时,由于前面不能是0,所以 001 ~ abc - 1,x,000 ~ 999, 那么种数为 (abc - 1) * 1000
    (2) abc,x,后面分成3种情况
         a. 当d < x 时,种数为0
         b.当 d = x 时,种数为000 ~ efg, efg+1种
         c. 当d > x 时,种数为000 ~ 999, 1000种
  • 特判下x作为第一位时,直接不讨论(1)中的情况当x == 0时,且作为第一位时(1)(2)二种情况都不讨论

三、代码

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int a, b;
int pow10(int x) {
   int ans = 1;
   while (x--) {
   	ans *= 10;
   }
   return ans;
}
//得到[l,r]区间的数 
int get(vector<int> v, int l, int r) {
   int ans = 0;
   for (int i = l; i <= r; i++) {
   	ans = ans * 10 + v[i];
   }
   return ans;
}
ll count(int n, int num) {
   //用一个vector保存n这个数
   vector<int> v;
   while (n) {
   	v.push_back(n % 10);
   	n /= 10;
   } 
   reverse(v.begin(), v.end());
   n = v.size();
   ll ans = 0;
   //是0的话跳过第一位 
   for (int i = 0 + !num; i < n; i++) {
   	int last10 = pow10(n - 1 - i);
   	if (i != 0) {
   		//代表不是第一位
   		//判断是否是0
   		ans += (get(v, 0, i - 1) - (num == 0)) * last10;
   	} 
   	//判断第二部分 d与 x的关系
   	if (v[i] == num) {
   		ans += get(v, i + 1, n - 1) + 1;
   	} else if (v[i] > num) {
   		ans += last10;
   	}
   	//当求第一位的时候
   	//只有num不等于0才有 只需要判断后面即可 
   	//判断第二部分 d与 x的关系
   }
   return ans;
}

int main() {
   while (scanf("%d%d", &a, &b), a) {
   	//注意交换a, b
   	if (a > b) swap(a, b);  
   	for (int i = 0; i < 10; i++) {
   		printf("%d ", count(b, i) - count(a - 1, i));
   	}	
   	puts("");
   }
   return 0; 
}