CAISZ有个女儿,已上幼儿园,在幼儿园中她学会了数数,但还不会做统计。现给定一个数字串,长度小于100,统计0,1,2……9 的个数。 好心的你帮帮她吧。
输入格式:
输入多组数字串,长度小于100;
输出格式:
数字串中的各个数字的个数,数字统计按照0,1,2,3。。9的顺序输出
输入样例:
在这里给出一组输入。例如:
11122233444445078
输出样例:
在这里给出相应的输出。例如:
0:1
1:3
2:3
3:2
4:5
5:1
6:0
7:1
8:1
9:0
代码
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
while(cin>>str)
{
int arr[10]={0};
for(int i=0;i<str.size();i++){
if(str[i]>='0'&&str[i]<='9'){
arr[str[i]-'0']++;
}
}
for(int i=0;i<10;i++){
printf("%d:%d\n",i,arr[i]);
}
}
}