GESP2025年3月真题题解
2026-06-22 20:17:58
发布于:广东
编程第一题
主要方法:这道题采用了方程的方法,所以在x固定的情况下,可得出此公式:
(x & y)+(x | y)
总的来说只需要while循环加上一个if判断即可,下面是题解:
#include <iostream>
#include <unordered_map>
#include <string>
#include <cctype>
using namespace std;
// 将字符串全部转为小写
string toLower(string s) {
for (int i = 0; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
return s;
}
int main() {
int n;
cin >> n;
unordered_map<string, int> cnt;
// 读入n个单词并计数
for (int i = 0; i < n; i++) {
string word;
cin >> word;
string low = toLower(word);
cnt[low]++;
}
// 找出现次数最多的单词
string res;
int max_num = 0;
for (auto &p : cnt) {
if (p.second > max_num) {
max_num = p.second;
res = p.first;
}
}
cout << res << endl;
return 0;
}
这里空空如也























有帮助,赞一个