文章

81

粉丝

2

获赞

530

访问

13.4k

头像
字母频率 题解:
P1019 贵州大学机试题
发布于2026年3月11日 14:00
阅读数 76

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
    string s;
    getline(cin, s);

    int cnt[26] = {0};

    for(char c : s){
        if(isalpha(c)){
            c = tolower(c);
            cnt[c - 'a']++;
        }
    }

    int max_val = 0;
    char ans = 'a';

    for(int i = 0; i < 26; i++){
        if(cnt[i] > max_val){
            max_val = cnt[i];
            ans = 'a' + i;
        }
    }

    cout << ans << " " << max_val;

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发