返回题解分享
讨论 / 题解分享/ 帖子详情

单词分析(编程题) - 题解

#include <bits/stdc++.h>
using namespace std;
int word[26];
int main()
{
    string str;
    int m = 0; // 记录最大值
    cin >> str;
    for (int i = 0; i < str.size(); i++)
    {
        word[str[i] - 'a']++;
        m = max(m, word[str[i] - 'a']);
    }
    for (int i = 0; i < 26; i++)
    {
        if (word[i] == m)
        {
            char ch = 'a' + i;
            cout << ch << endl;
            cout << word[i] << endl;
            break;
        }
    }
    return 0;
}
0 回复 0 转发 0 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!