题目描述
从键盘输入一行文本,统计其中数字字符‘0’~‘9’出现的频率并输出。没出现的不需要输出。
输入
一行文本,长度不超过1000。
输出
按照从0到9顺序输出统计结果。每个数字的信息占一行,如“0:2”表示数字字符0出现了2次。
样例输入 Copy
Hello No 007.
样例输出 Copy
0:2 7:1
#include <bits/stdc++.h>
using
namespace
std;
int
main()
{
int
i,j,cnt;
char
a[1010],b[10]={
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
};
cin.getline(a,1010);
for
(j=0;j<10;j++)
{
for
(i=0,cnt=0;a[i]!=
'\0'
;i++)
{
if
(a[i]==b[j])
{
cnt++;
}
}
if
(cnt>0)
{
printf
(
"%d:%d\n"
,j,cnt);
}
}
return
0;
}