结合紫书的分析,按照诸位判断并且计算即可,具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
typedef long long LL;
LL res1[10], res2[10];
void solve(char data[],LL res[]){
int length = strlen(data);
int t = 1;
for (int i = 0; i < length-1; i++){
t *= 10;
res[0] -= t;
}
for (int i = 0; i < length; i++){
int temp = data[i] - '0';
for (int j = 0; j < temp; j++){
res[j] += t;
}
for (int j = 0; j < 10; j++){
res[j] += temp*((length - 1 - i)*t / 10);
}
res[temp] += atoi(data + i + 1)+1;
t /= 10;
}
}
int main(){
LL a, b;
while (cin >> a >> b){
if (a == 0 && b == 0) break;
char data1[10], data2[10];
if (a > b) swap(a,b);
a--;
memset(data1, 0, sizeof(data1));
memset(data2, 0, sizeof(data2));
sprintf(data1, "%d", a);
sprintf(data2, "%d", b);
memset(res1, 0, sizeof(res1));
memset(res2, 0, sizeof(res2));
solve(data1, res1);
solve(data2, res2);
for (int i = 0; i < 9; i++)
cout << res2[i] - res1[i] << " ";
cout << res2[9] - res1[9] << endl;
}
return 0;
}