PATB1021个数统计

参考代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>

int main()
{
	char str[1010];
	int i = 0;
	fgets(str, 1010, stdin);
	while (str[i] != '\n')
		i++;
	str[i] = '\0';
	int len = strlen(str);

	int count[10] = { 0 };
	for (int i = 0; i < len; i++)
	{
		count[str[i] - '0']++;
	}

	for (int i = 0; i < 10; i++)
	{
		if (count[i] != 0)
		{
			printf("%d:%d\n", i, count[i]);
		}
	}
	system("pause");
	return 0;
}
posted @ 2019-07-17 19:25  睿晞  阅读(146)  评论(0编辑  收藏  举报