hdoj-1004-Let the Balloon Rise(map排序)

map按照value排序

 1 #include <iostream> 
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <map>
 5 #include <vector>
 6 #include <utility>
 7 using namespace std;
 8 typedef pair<string, int> PAIR;
 9 bool cmp_by_value(const PAIR& lhs, const PAIR& rhs) {
10     return lhs.second > rhs.second;
11 }
12 map<string ,int> ship;
13 int main() {
14     int n;
15     while (cin>>n, n) {
16         ship.clear();
17         for (int i=0; i<n; i++) {
18             string tmp;
19             cin>>tmp;
20             ship[tmp]++;
21         }
22         vector<PAIR> vec(ship.begin(), ship.end());
23         sort(vec.begin(), vec.end(), cmp_by_value);
24         cout<<vec.begin()->first<<endl;
25     }
26     return 0;
27 }

 

posted @ 2018-05-03 10:45  朤尧  阅读(308)  评论(0编辑  收藏  举报