PTAL1-003 single digit statistics

L1-003 One-digit statistics (15 points)
Given a k-digit integer N=dk−110k−1+...+d1101+d0 (0≤di≤9, i=0,...,k−1, dk−1 >0), please write a program to count the number of occurrences of each different single digit. For example: Given N=100311, there are 2 0s, 3 1s, and 1 3.
Input format:
Each input contains 1 test case, that is, a positive integer N with no more than 1000 digits.
Output format:
For each different one digit in N, output the digit D and the number of occurrences M in N in a line in the format of D:M. It is required to output in ascending order of D.
Input sample:
100311

Sample output:
0:2
1:3
3:1

#include<stdio.h>
#include<string.h>
int main()
{
    
    	int i=0,h,n;
char x[1000];
gets(x);
h=strlen(x);
n=0;
   typedef struct tjjg{
    
    
   	int q;
   	int e;
   	} tj;
   tj a[10];
   for(i=0;i<10;i++){
    
    
   a[i].q=i;a[i].e=0;}
   for(i=0;i<10;i++)
   while(n<h){
    
    
   	for(i=0;i<10;i++) 
   	if((x[n]-48)==i)
   	 a[i].e++;
   	n++;
   }
   for(i=0;i<10;i++)
   if(a[i].e!=0)
    printf("%d:%d\n",a[i].q,a[i].e);
}

Guess you like

Origin blog.csdn.net/weixin_42403632/article/details/104118445