B1021个位数统计

B1021个位数统计

#include<cstdio>
#include<string>

int main()
{
	char s[1000];
	scanf("%s",s);
	int count[10]={0};
	for(int i=0;s[i]!='\0';i++)
	{
		count[s[i]-'0']++;
	}
	for(int i=0;i<10;i++)
	{
		if(count[i]!=0)
		{
			printf("%d:%d\n",i,count[i]);
		}
	}
	return 0;
}

1、第一次用gets(s)时不通过PAT测试,运行没问题但是不知道为什么

2、注意for循环的条件是s[i]!='\0';

发布了61 篇原创文章 · 获赞 0 · 访问量 589

猜你喜欢

转载自blog.csdn.net/qq_38054511/article/details/103963676