#include <iostream>
using namespace std;
//统计数字出现次数利用数组进行统计
int a[15]={0};
int m, n,s;
int main() {
cin >> m >> n;
for (int i = m; i<= n; i++) {//遍历数组中的数
int s = i;//对数组中的数进行数位拆分
while (s != 0)//取到数组中的一位数,直到把每一位的数都统计完
{
int t = s % 10;//取到一位的数
s = s / 10;//更新位数都统计
a[t]++;//对统计出来的数进行累加
}
}
for (int i = 0; i <= 9; i++) {
cout << a[i] <<" ";
}
}
数组的利用:统计给出数中数字出现的次数
最新推荐文章于 2024-05-09 20:18:18 发布