1042 字符统计(C语言)

设计思路:
  • 利用数组存储
编译器:C (gcc)
#include 
#include 

int main()
{
     
    int keyboard[26] = {
     0}, max = 25;
    char ch;
    int i;
    while((ch = getchar()) != '\n'){
     
        if(isalpha(ch)){
     
            keyboard[tolower(ch) - 'a']++;
        }
    }
    for(i = 25; i >= 0; i--){
     
        if(keyboard[i] >= keyboard[max]){
     
            max = i; 
        }
    }
    printf("%c %d\n", max + 'a', keyboard[max]);
    return 0;
}   

你可能感兴趣的:(PAT,乙级,PAT乙级,C)