1047

作者: 峡迩 | 来源:发表于2017-09-03 18:16 被阅读0次
    // PATn.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include<iostream>
    #include<string>
    #include<map>
    #include<vector>
    #include<algorithm>
    
    
    using namespace std;
    
    int main()
    {
        unsigned n = 0;
        cin >> n;
    
        map<string, unsigned> total_grade;
        string tmp1;
        unsigned tmp2;
        
        for (unsigned i = 0; i < n; ++i)
        {
            cin >> tmp1 >> tmp2;
            string tmp1_tmp = tmp1.substr(0, tmp1.find("-"));
            if (total_grade.find(tmp1_tmp) != total_grade.cend())
            {
                total_grade.at(tmp1_tmp) += tmp2;
            }
            else
            {
                total_grade[tmp1_tmp] = tmp2;
            }
        }
    
        vector<pair<string, unsigned>> tmp_total_grade(total_grade.begin(), total_grade.end());
        sort(tmp_total_grade.begin(), tmp_total_grade.end(), [&](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.second > rh.second; });
    
        cout << tmp_total_grade[0].first << " " << tmp_total_grade[0].second;
        
    
        system("pause");
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:1047

          本文链接:https://www.haomeiwen.com/subject/imyjjxtx.html