hdu 1004 Let the Balloon Rise

这题主要用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;
}


 

 

posted @ 2011-10-23 19:59  liuwu265  阅读(127)  评论(0编辑  收藏  举报