题目大意:求1到m的数位中0~9出现的次数。
解题思路:从一到m循环,求出每位数。
ac代码:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n, sum[10], m, temp, temp2;
char a[1000];
scanf("%d", &n);
while (n--){
scanf("%d", &m);
memset(sum, 0, sizeof(sum));
for (int i=1; i<=m; i++){
temp = i;
while (temp){
temp2 = temp%10;
temp = temp/10;
sum[temp2]++;
}
}
for (int i=0; i<10; i++)
printf(i==0?"%d":" %d", sum[i]);
printf("\n");
}
return 0;
}