您的位置:首页 > 其它

UVa1225 Digit Counting

2016-03-30 17:05 295 查看
《算法竞赛入门经典(第2版)》 作者:刘汝佳 

第三章习题3-3 统计一个顺次排列的数字串中0...9每个数码出现的次数
https://uva.onlinejudge.org//index.php?option=com_onlinejudge&Itemid=8&category=827
----------------------------------------------E3-3.cpp-------------------------------------------

#include <stdio.h>

#include <string.h>

#define LOCAL

int main()

{

#ifdef LOCAL
freopen("E3-3.in", "r", stdin);

#endif
int kase;
scanf("%d", &kase);
while(kase--) {
int num, count[10];
memset(count, 0, sizeof(count));
scanf("%d", &num);
for(int i = 1; i <= num; i++) {
char s[5];
sprintf(s, "%d", i);
for(int i = 0; i < strlen(s); i++)
count[ s[i] - '0' ] ++;
}
for(int i = 0; i <= 9; i++)
if(i == 0) printf("%d", count[i]);
else printf(" %d", count[i]);
printf("\n");

}
return 0;

}

---------------------------------------E3-3.in的分界线---------------------------------

20

7138

4309

1199

9830

1161

4787

3148

4729

6715

5635

9069

2122

364

9577

5290

953

588

5871

2315

579
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: