关于C++英文统计程序

关于C++英文统计
英文里出现最频繁的字母是小写e。你希望统计一下,在一段英文文章里出现最频繁的双字母组合和三字母组合是什么?
输入样例#1:
Talk is cheap. Show me the code. Good design adds value faster than it adds cost. In theory, theory and practice are the same. In practice, they're not. Debugging is twice as hard as writing the code in the first place.
输出样例#1:
he
the


```c++
#include <bits/stdc++.h>
using namespace std;
map<string,int>d;
int main()
{
    string s,ans;
    int big=0;
    while(cin>>s)
    {
        d[s]++;
    }
    map<string,int>::iterator mit;
    for (mit=d.begin();mit!=d.end();mit++)
    {
        int cnt=mit->second;
        if (cnt>big)
        {
            big=cnt;
            ans=mit->first;
        }
        else if(cnt==big)
        {
            if (mit->first<ans)
            {
                ans=mit->first;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

```

“该回答引用ChatGPT”
参考下面的代码

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

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

    // 统计双字母组合的频率
    map<string, int> double_letters;
    for (int i = 0; i < s.size() - 1; i++) {
        string double_letter = s.substr(i, 2);
        double_letters[double_letter]++;
    }

    // 统计三字母组合的频率
    map<string, int> triple_letters;
    for (int i = 0; i < s.size() - 2; i++) {
        string triple_letter = s.substr(i, 3);
        triple_letters[triple_letter]++;
    }

    // 查找最频繁的双字母组合
    string max_double_letter = "";
    int max_double_letter_count = 0;
    for (auto it = double_letters.begin(); it != double_letters.end(); it++) {
        if (it->second > max_double_letter_count) {
            max_double_letter = it->first;
            max_double_letter_count = it->second;
        }
    }

    // 查找最频繁的三字母组合
    string max_triple_letter = "";
    int max_triple_letter_count = 0;
    for (auto it = triple_letters.begin(); it != triple_letters.end(); it++) {
        if (it->second > max_triple_letter_count) {
            max_triple_letter = it->first;
            max_triple_letter_count = it->second;
        }
    }

    cout << max_double_letter << endl << max_triple_letter << endl;
    return 0;
}


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^