You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
951 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
// 暴力法获取从1开始到n,有多少个指定的x,[类似于前缀和的思路]
// 从0到10的8次方就是枚举每一位一个测试点是 8*10^8,会超时,不可取
int force_count(int n, int x) {
int res = 0;
for (int i = 1; i <= n; i++) {
int t = i;
while (t) {
if (t % 10 == x) res++;
t /= 10;
}
}
return res;
}
int main() {
int a, b;
// 当读入一行为0 0时表示输入终止且该行不作处理,注意这里 a||b的使用方法
while (cin >> a >> b, a || b) {
if (a > b) swap(a, b); // 这题还玩小的在后大的在前需要我们用代码判断shit!
// 计算0--9的每一个数出现的次数
for (int i = 0; i <= 9; i++)
cout << force_count(b, i) - force_count(a - 1, i) << ' ';
cout << endl;
}
return 0;
}