hdu 1004 Let the Balloon Rise

hdu 1004 Let the Balloon Rise

map的应用

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<map>
 4 #include<string>
 5 using namespace std;
 6 int main()
 7 {
 8     freopen("input.txt","r",stdin);
 9     map<string,int>balloons;
10     int n;
11     string s;
12     while(cin>>n && n)
13     {
14         balloons.clear();
15         while(n--)
16         {
17             cin>>s;
18             balloons[s]++;
19 
20         }
21         map<string,int>::iterator it;
22         int Max = 0;
23         string pos;
24         for(it = balloons.begin(); it != balloons.end(); it++)
25         {
26             if((*it).second > Max)
27             {
28                 Max = (*it).second;
29                 pos = (*it).first;
30             }
31         }
32         cout<<pos<<endl;
33 
34     }
35     return 0;
36 }