1042 character statistics, C

Summary explanations directory

#include <stdio.h>
int main()
{
    char a[1001]={0};
    int b[26]={0};
    int i=0,n=0,max=-1,x=0;

    scanf("%[^\n]",a);

    while(a[i])
    {
        if(a[i]>64 && a[i]<91)
            {n=a[i]-65;b[n]++;}
        else if(a[i]>96 && a[i]<123)
            {n=a[i]-97;b[n]++;}
        i++;
    }

    i=0;
    while(i<26)
    {
        if(max<b[i])
        {
            max = b[i];
            x = i;
        }
        i++;
    }

    x = x+97;
    printf("%c %d",x,max);


    return 0;
}
Published 44 original articles · won praise 0 · Views 866

Guess you like

Origin blog.csdn.net/weixin_43916400/article/details/104585419