杭电oj -1004 Let the Balloon Rise(C++) STL

杭电oj -1004 Let the Balloon Rise(C++) STL
分析:用set容器存键值和实值 输出实值最大的对应的key

#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
	map<string,int> m;
	string color;
	int n;
	while(cin >> n && n != 0)
	{
		m.clear(); 
		while(n--)
		{
			cin >> color;
			m[color]++;
		}
		int max = -1001;	      //存实值
		string maxc;		   //存出现最多的对应的颜色 即最大实值对应的Key
		for(auto it = m.begin();it != m.end();++it)
		{
			if((*it).second > max)
			{
				maxc = (*it).first;
				max = (*it).second;
			}
		}
		cout << maxc << endl;
	}
	return 0;
}