题目背景
由于洛谷上裸STL的题目实在太少了,森子十分绝望以至于自己出了一道题 来霍霍萌新
题目描述
给出一篇英语文章,请你找出其中出现次数最多的单词
-
由于森子并不喜欢大写,所以你需要把所有的单词都转换成小写的形式
-
如果出现多个单词出现次数相同的情况,请输出转换成小写后字典序最小的单词
-
英语的缩写看成一个单词
例如,I'm看成一个单词,不视作I和am两个单词
输入格式
一篇英语文章(不包含任何标点符号,缩写除外),词数不定
输出格式
出现次数最多的单词 和 该单词出现的次数 ,以空格分隔
题意翻译
中文题面还需要翻译成英文吗qwq
说明/提示
数据范围:
单词的总数 nn 满足 0 < n <2\times 10^70<n<2×107
单词的种类数 cc 满足 0< c <1\times 10^30<c<1×103
输入输出样例
输入 #1
I love ccnuacm and I will learn algorithms forever输出 #1
i 2输入 #2
Hey hey you you I don't like your girlfriend no way no way I think somebody need a new one输出 #2
hey 2
题解
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mo = 1e3;
const int N = 1e5 + 5;
void solve()
{
map<string, int >mp;
vector<string>ans;
string s;
while (cin >> s)
{
transform(s.begin(),s.end(),s.begin(),::tolower);
auto it=mp.find(s);
if(it!=mp.end())mp[s]++;
else mp[s]=1;
}
string anss="";
int mx=0;
for(auto [st,len]:mp)
{
if(len>mx)
{
mx=len;
anss=st;
}
}
cout<<anss<<' '<<mx;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}