版权声明:假装有个原创声明……虽然少许博文不属于完全原创,但也是自己辛辛苦苦总结的,转载请注明出处,感谢! https://blog.csdn.net/m0_37454852/article/details/86656750
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include <map>
using namespace std;
map<string, int> Num;//看错题了,我以为最大是10^24呢,2^24的话long int完全够用,不必用string了
string str;
int main()
{
int M, N, dominant_num = 0;
scanf("%d %d", &M, &N);
N *= M;
for(int i=0; i<N; i++)//共输入N*M个
{
cin>>str;
Num[str]++;//计数
}
for(map<string, int>::iterator it = Num.begin(); it != Num.end(); it++)//遍历寻找最多数量的那个
{
if(it->second > dominant_num)
{
dominant_num = it->second;
str = it->first;//并用str存储下来
}
}
cout<<str;//之后打印
return 0;
}