zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    十天冲刺:第四天
    十天冲刺:第三天
    会议2.3
    会议2.2
    会议2.1
    团队绩效管理
    Alpha版(内部测试版)发布
    意见汇总
    建议汇总
    会议1.10
  • 原文地址:https://www.cnblogs.com/langyao/p/8984226.html
Copyright © 2011-2022 走看看