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

 

Sample Output

#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

void Cal(char *s, int *num)
{
    int i, j, k, n, t, m = atoi(s);
    n = strlen(s);
    for(i = k = 1; i < n; i++)
        k *= 10, num[0] -= k;
    for(i = 0; i < n; i++, k /= 10){
        for(j = 0; j < s[i] - '0'; j++)
            num[j] += k;
        for(t = 0; t < 10; t++)
            num[t] += k / 10 * (n - i - 1) * j;
        if(i + 1 < n) num[j] += atoi(s + i + 1);
        num[j]++;
    }
}
int main()
{
    char s[22];
    int i, n, m, a[11] = {0}, b[11] = {0};
    while(~scanf("%d %d", &n, &m) && !(m==0 && n==0)){
        if(n > m) 
            swap(n, m);
        memset(a, 0, sizeof(a));
        sprintf(s, "%d", n - 1);
        Cal(s, a);
        memset(b, 0, sizeof(b));
        sprintf(s, "%d", m);
        Cal(s, b);
        for(i = 0; i < 9; i++)
            printf("%d ", b[i] - a[i]);
        printf("%d\n", b[9] - a[9]);
    }
}

 

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐