习题3-3 数数字(Digit Counting,ACM/ICPC Danang 2007,UVa1225)

原题链接:https://vjudge.net/problem/UVA-1225
分类:数组
备注:暴力
代码如下:

#include<stdio.h>
const int maxn = 10000 + 5;
int T, n;
int main(void)
{
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &n);
		int ans[10] = { 0 };
		for (int i = 1; i <= n; i++)
		{
			int tp = i;
			while (tp) { ans[tp % 10]++; tp /= 10; }
		}
		for (int i = 0; i <= 9; i++)printf("%d%c", ans[i], i == 9 ? '\n' : ' ');
	}
	return 0;
}
发布了22 篇原创文章 · 获赞 23 · 访问量 512

猜你喜欢

转载自blog.csdn.net/TK_wang_/article/details/104361574