Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Count the number of occurrences of each numeric character in 1 string, and output it in descending order.
Count the number of occurrences of each numeric character in 1 string, and output it in descending order.
int c[ 10]={0},b[ 10]={0, 1,2,3,4,5,6,7,8,9 };

int i,j,t;

char a[ 1000];

Get (a);

for(I = 0; a[I]; i++)

if(a[I]& gt; = ' 0 ' & amp& ampa[I]& lt; ='9')

c[a[I]= ' 0 ']++;

for(I = 0; I< 10; i++)

for(j = I+ 1; j & lt 10; j++)

if(c[I]& gt; c[j])

{

t = c[I]; c[I]= c[j]; c[j]= t;

t = b[I]; b[I]= b[j]; b[j]= t;

}

for(I = 0; I< 10; i++)

printf("%d %d\n ",b[i],c[I]);