chaper3_exerise_Uva1225_digit_counting

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<cstring>
 4 using namespace std;
 5 const int maxn = 10010;
 6 
 7 int main(void)
 8 {
 9     int N, n;                  //N组数据 , n前n个整数顺次
10     cin >> N;
11     for (int i = 0; i < N; i++)
12     {
13         char buf[maxn];
14         int count[10] = {0};
15         cin >> n;
16         for (int i = 1; i <= n; i++)
17         {
18             sprintf(buf,"%d",i);    
19             for (int j = 0; j < strlen(buf); j++)
20             {
21                 count[buf[j]-'0']++;
22             }
23         }    
24         for (int k = 0; k < 9; k++)
25             cout << count[k] << ' ';     //注:UVa里不允许多输出空格
26         cout << count[9] << endl;
27     }
28     return 0;
29 } 

 

posted @ 2016-06-14 17:42  douzujun  阅读(170)  评论(0编辑  收藏  举报