1 条题解
-
0
#include <iostream> #include <cctype> #include <string> #include <map> #include <cstdio> using namespace std; int main() { string line; map<string, int> wordCount; string currentWord = ""; while (getline(cin, line)) { if (line=="")break; for (int i = 0; i < line.size(); i++) { unsigned char c = line[i]; if (isalnum(c)) { currentWord += tolower(c); } else { if (!currentWord.empty()) { wordCount[currentWord]++; currentWord = ""; } } } if (!currentWord.empty()) { wordCount[currentWord]++; currentWord = ""; } } if (!currentWord.empty()) { wordCount[currentWord]++; currentWord = ""; } int max_count = 0; for (map<string, int>::iterator it = wordCount.begin(); it != wordCount.end(); it++) { if (it->second > max_count) { max_count = it->second; } } cout << max_count << " occurrences" << endl; for (map<string, int>::iterator it = wordCount.begin(); it != wordCount.end(); it++) { if (it->second == max_count) { cout << it->first << endl; } } return 0; }
- 1
信息
- ID
- 584
- 时间
- 1000ms
- 内存
- 10MiB
- 难度
- 7
- 标签
- 递交数
- 9
- 已通过
- 0
- 上传者