1 条题解
-
0
C++ :
#include <cstdio> #include <iostream> #include <string> #include <unordered_map> #include <cctype> using namespace std; int main(){ string line; if(!getline(cin, line)) return 0; unordered_map<string, int> cnt; string cur; for(size_t i = 0; i <= line.size(); i++){ char ch = (i < line.size()) ? line[i] : '\0'; if(isalnum((unsigned char)ch)){ cur.push_back((char)tolower((unsigned char)ch)); /* 统一小写 */ }else if(!cur.empty()){ cnt[cur]++; cur.clear(); } } string bw; int bc = -1; for(unordered_map<string, int>::iterator it = cnt.begin(); it != cnt.end(); ++it){ /* 次数多者优先;次数相同取字典序最小 */ if(it->second > bc || (it->second == bc && it->first < bw)){ bw = it->first; bc = it->second; } } printf("%s %d\n", bw.c_str(), bc); return 0; }
- 1
信息
- ID
- 2613
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者