版本4和9间的区别 (跳过第5版)
于2006-04-21 21:33:30修订的的版本4
大小: 1825
编辑: czk
备注:
于2008-06-01 13:23:49修订的的版本9
大小: 713
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 1: 行号 1:
## page was renamed from 程序设计练习14——zju2104——Let the Balloon Rise
行号 5: 行号 4:
Time limit: 1 Seconds

Memory limit: 32768K

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.
This year, they decide to leave this lovely job to you.

== Input ==
Input contains multiple test cases. Each test case starts with a number N (0 < N < 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.


== Output ==
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.


== Sample Input ==
{{{5
green
red
blue
red
red
3
pink
orange
pink
0
}}}

== Sample Output ==
{{{red
pink
}}}


------
行号 51: 行号 12:
bool less_map(map<string, int>::value_type v1, map<string, int>::value_type v2)\ {
  return v1.second < v2.second;
bool less_map(map<string, int>::value_type v1, map<string, int>::value_type v2) {
   return v1.second < v2.second;
行号 55: 行号 16:
int main()
{
  while(1) {
    int n;
    cin >> n;
if(n==0) break;
    map<string, int> colors;
    for(int i = 0; i < n; i++) {
      string color;
      cin >> color;
colors[color]++; //automatic insert (color,0) pair when key color doesn't exist
int main() {
   while (true) {
        int n;
        cin >> n;
    
if (n==0)
            
break;
     map<string, int> colors;
        for (int i = 0; i < n; i++) {
            string color;
            cin >> color;
      
colors[color]++;
        }
        co
ut << max_element(colors.begin(), colors.end(), less_map)->first << endl;
行号 67: 行号 30:
    cout << max_element(colors.begin(), colors.end(), less_map)->first << endl;
  }
}
}}}
}}}}

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 (true) {
  14         int n;
  15         cin >> n;
  16         if (n==0) 
  17             break;
  18         map<string, int> colors;
  19         for (int i = 0; i < n; i++) {
  20             string color;
  21             cin >> color;
  22             colors[color]++;
  23         }
  24         cout << max_element(colors.begin(), colors.end(), less_map)->first << endl;
  25     }

}

zju2104 (2008-06-01 13:23:49由czk编辑)

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