P1554 梦中的统计题解

题目传送门

总结

1、用桶计数,适合数量不多的场景,比如本题,就是记录(0 sim 9)
2、考查数位分离

#include <bits/stdc++.h>

using namespace std;
const int N = 11;
int a[N];

int main() {
    int m, n;
    cin >> m >> n;
    for (int i = m; i <= n; i++) {
        int t = i;
        while (t) {
            int c = t % 10;
            a[c]++;
            t /= 10;
        }
    }
    for (int i = 0; i <= 9; i++)cout << a[i] << " ";
    return 0;
}
原文地址:https://www.cnblogs.com/littlehb/p/15039223.html