比赛链接

A题主要是map的使用,比赛的时候问了下队友,下次要记住了

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL T,n;
map<string,int> mp1,mp2;

int main()
{
    cin>>T;
    while(T--)
    {
        mp1.clear();mp2.clear();
        cin>>n;
        for(int i=0;i<n;i++)
        {
            string str;
            int t;
            cin>>str>>t;
            if(mp1[str]<t)
            {
                mp2[str]=mp1[str];
                mp1[str]=t;
            }
            else if(mp2[str]<t)
            {
                mp2[str]=t;
            }
        }
        int ans=0;
        for(map<string,int>::iterator it=mp1.begin();it!=mp1.end();++it)
            ans+=it->second;
        for(map<string,int>::iterator it=mp2.begin();it!=mp2.end();++it)
            ans+=it->second;
        cout<<ans<<endl;
    }
}
hdu_6015

相关文章: