1. 程式人生 > >HDU 1004 Let the Balloon Rise (STL map)

HDU 1004 Let the Balloon Rise (STL map)

HDU 1004 Let the Balloon Rise

題面

題解

#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<set>
#include<map>
#include<queue>

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;

int main() {
	std::ios::sync_with_stdio(false);
	int N, max;
	string ans;
	string color;
	while (cin >> N && N) {
		map<string, int>mp;
		max = 0;
		for (int i = 0; i < N; i++) {
			cin >> color;

			if (!mp.count(color)) {
				mp.insert(pair<string, int>(color, 1));
			}
			else {
				mp[color]++;
			}
		}
		
		map<string, int>::iterator iter;
		for (iter = mp.begin(); iter != mp.end(); iter++) {
			if (iter->second > max) {
				max = iter->second;
				ans = iter->first;
			}
		}
		cout << ans << endl;
	}
	return 0;
}