牛客网PAT练习场-个位数的统计
思路:每接受一个字符,便统计一次即可
题目地址:https://www.nowcoder.com/questionTerminal/a2063993dd424f9cba8246a3cf8ef445
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int main(){ 6 int a[10]={0}; 7 char c; 8 scanf("%c",&c); 9 while(c>='0'&&c<='9'){ 10 while(c=getchar()) 11 a[c-'0']++; 12 scanf("%c",&c); 13 } 14 for(int i=0;i<=9;i++){ 15 if(a[i]!=0){ 16 printf("%d:%d\n",i,a[i]); 17 } 18 } 19 return 0; 20 }