这题主要用Map来实现

#include <iostream>
#include <map>
#include <cstring>
using namespace std;
int main()
{
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
	int n;
	map<string,int>m;
	string str;
	while(scanf("%d",&n)==1 && n)
	{
		m.clear();
		for(int i=0;i<n;i++)
		{
			cin >> str;
			m[str]++;
		}
		map<string,int>::iterator p,q;
		int max=-1;
		for(p=m.begin(); p!=m.end(); p++)
			if(p->second > max)
			{
				max=p->second;
				q=p;
			}
		cout << q->first << endl;
	}
	return 0;
}


 

 

相关文章:

  • 2021-06-02
  • 2022-01-11
  • 2022-12-23
  • 2022-03-03
  • 2022-02-10
  • 2021-11-05
  • 2021-12-29
猜你喜欢
  • 2021-06-15
  • 2021-09-18
  • 2021-09-06
  • 2022-12-23
相关资源
相似解决方案