没难度上代码。
#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
struct node {
string s;
int cnt;
};
vector<node> ans;
bool cmp (node a, node b) {
if (a.cnt != b.cnt) return a.cnt > b.cnt;
return a.s < b.s;
}
int main() {
string s;
getline(cin, s);
for (int i = 0; i < s.size(); i++) {
string temp;
while (isalnum(s[i])) {
temp += tolower(s[i++]);
}
if (temp != "") {
mp[temp]++;
}
}
for (auto it : mp)
ans.push_back({it.first, it.second});
sort (ans.begin(), ans.end(), cmp);
cout << ans[0].s << " " << ans[0].cnt;
}
该博客主要探讨了一段代码,这段代码读取输入字符串,将连续的字母数字字符合并,并统计出现频率。然后将结果存储在结构体中,并根据频率和字母顺序进行排序。文章突出了字符串处理和算法应用的关键技巧。
144

被折叠的 条评论
为什么被折叠?



