Let the Balloon Rise

http://acm.zju.edu.cn/show_problem.php?pid=2104

   1 /*Written by czk*/
   2 #include <iostream>
   3 #include <string>
   4 #include <map>
   5 #include <algorithm>
   6 using namespace std;
   7 
   8 bool less_map(map<string, int>::value_type v1, map<string, int>::value_type v2) {
   9     return v1.second < v2.second;
  10 }
  11 
  12 int main() {
  13     while (1) {
  14         int n;
  15         cin >> n;
  16         if (n==0) break;
  17         map<string, int> colors;
  18         for (int i = 0; i < n; i++) {
  19             string color;
  20             cin >> color;
  21             colors[color]++; //automatic insert (color,0) pair when key color doesn't exist
  22         }
  23         cout << max_element(colors.begin(), colors.end(), less_map)->first << endl;
  24     }

}

ch3n2k.com | Copyright (c) 2004-2020 czk.