SDNU 1014.书的页码问题
Time Limit: 1000 MS Memory Limit: 32768 KB
Total Submission(s): 1109 Accepted Submission(s): 256
Description
对于一本共有n页的书,它的页码从1开始编号,一直到n,页码中没有无用的0,则该书页码中分别共用到了多少个0,1,2,3,4,5,6,7,8,9?
Input
书的页数n(1 <= n <= 1000 0000)
Output
十个数以空格隔开,分别表示0,1,2,3,4,5,6,7,8,9这十个数字出现的次数。
Sample Input
10
Sample Output
1 2 1 1 1 1 1 1 1 1
水题,直接暴力,附上ac代码:
#include <stdio.h>
int main()
{
int n,m;
int a[10] = {0};
scanf("%d",&n);
for(i = 1; i < n + 1; i++)
{
if(i > 9)
{
int j = i;
while (j)
{
m = j % 10;
a[m]++;
j = j / 10;
}
}
else
a[i]++;
}
for(int i = 0; i < 9; i++)
printf("%d ",a[i]);
printf("%d",a[9]);
return 0;
}