参考代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
int main()
{
char str[1010];
int i = 0;
fgets(str, 1010, stdin);
while (str[i] != '
')
i++;
str[i] = ' ';
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
", i, count[i]);
}
}
system("pause");
return 0;
}