1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include <bits/stdc++.h> using namespace std; const int N = 15; typedef long long ll; ll l = 0, r = 0, dp[N] = { 0 }, mi[N] = { 0 }; ll ans1[N] = { 0 }, ans2[N] = { 0 }; int a[N] = { 0 };
void solve(ll n, ll* ans) { int len = 0; ll tmp = n; while (n) a[++len] = n % 10, n /= 10;
for (int i = len; i >= 1; --i) { for (int j = 0; j < 10; j++) ans[j] += dp[i - 1] * a[i];
for (int j = 0; j < a[i]; j++) ans[j] += mi[i - 1];
tmp -= mi[i - 1] * a[i], ans[a[i]] += tmp + 1;
ans[0] -= mi[i - 1]; } }
int main() { mi[0] = 1ll;
for (int i = 1; i <= 13; ++i) { dp[i] = dp[i - 1] * 10 + mi[i - 1]; mi[i] = 10ll * mi[i - 1]; } while (1) { scanf("%lld%lld", &l, &r); if (l > r) swap(l, r); if (l == 0 && r == 0) break; memset(ans1, 0, sizeof(ans1)); memset(ans2, 0, sizeof(ans2)); memset(a, 0, sizeof(a)); solve(r, ans1), solve(l - 1, ans2); for (int i = 0; i < 10; ++i) printf("%lld ", ans1[i] - ans2[i]); cout << "\n"; } return 0; }
|