社区讨论
求助大神
B4262[GESP202503 三级] 词频统计参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mhjd4lex
- 此快照首次捕获于
- 2025/11/04 00:36 4 个月前
- 此快照最后确认于
- 2025/11/04 00:36 4 个月前
CPP
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string words[100];
int counts[100] = {0};
for (int i = 0; i < n; i++) {
cin >> words[i];
for (char &c : words[i]) {
c = tolower(c);
}
counts[i] = 1;
for (int j = 0; j < i; j++) {
if (words[j] == words[i]) {
counts[j]++;
counts[i] = 0;
break;
}
}
}
int maxCount = 0;
string maxWord = "";
for (int i = 0; i < n; i++) {
if (counts[i] > maxCount) {
maxCount = counts[i];
maxWord = words[i];
}
}
cout << maxWord << endl;
return 0;
}
老师看了要急眼,怎么写的更好,球大家按照我的水平写,比这个难的语句看不懂,蟹蟹
回复
共 2 条回复,欢迎继续交流。
正在加载回复...