PAT(Basic Level)_1042_字符统计

来源:互联网 发布:地税优化营商环境 编辑:程序博客网 时间:2024/05/20 10:52
#include<iostream>#include<cstring>#include<cstdio>using namespace std;int main(){    int cnt[26]={};    char str[1001];    cin.getline(str,1001);    int len=strlen(str);    for(int i=0;i<len;i++){        if(str[i]>='A' && str[i]<='Z'){            str[i]+=32;        }        if(str[i]>='a' && str[i]<='z'){            cnt[str[i]-'a']++;        }    }    int max=0;    for(int i=0;i<26;i++){        if(cnt[i]>cnt[max]){            max=i;        }    }    printf("%c %d",max+'a',cnt[max]);    return 0;}
阅读全文
0 0
原创粉丝点击