PAT (Basic Level) Practice (中文)
announcement
PAT original site users can https://patest.cn/bind_old_pat_user bound to A title fight Account page. After binding, the site of the original PAT submission will be incorporated into the title fight A website user corresponding topic focus.
1021 median statistics (15 points)
Given a k-bit integer N = d k 1-10 k-1 + ⋯ + d 1 10 1 + d 0 (0≤d i ≤ 9, i = 0, ⋯, k-1, d k-1> 0), write a program to count the number of each of the different single digits appear. For example: given N = 100311, there are two 0,3 1 2, and 1 3.
Input formats:
Each input comprises a positive integer one test, i.e. one of no more than 1000 N.
Output formats:
For each of the N different digit to D:M
the digital format of the output bit in a row D
and the number of occurrences in the N M
. Required by the D
ascending output.
Sample input:
100311
Sample output:
0:2
1:3
3:1
#include<iostream>
#include<cstring>
using namespace std;
int main(void){
char str[1009] ;
int a[10];
while( scanf(" %s",str)!=EOF){
memset(a,0,sizeof(a));
for( int i=0;i<strlen(str);i++){
a[ str[i] - '0']++;
}
for( int i=0;i<10;i++){
if( a[i] )
printf("%d:%d\n",i,a[i]);
}
}
return 0;
}