标签:string max else using xid ima pair inner image
输入样例:
6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61
输出样例:
11 176
思路是建立一张表,以队伍编号为关键字,以队伍总成绩为关键字对应的值。统计时直接查表。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
struct TeamMember
{
int idOfTeam,idOfMember,score;
friend istream& operator>>(istream& str,TeamMember& m)
{
cin>>m.idOfTeam;
getchar();
cin>>m.idOfMember;
getchar();
cin>>m.score;
}
};
void countWinner(TeamMember* p,int n);
int main()
{
int n;
cin>>n;
TeamMember* p=new TeamMember[n];
for(int i=0;i<n;i++)
cin>>p[i];
countWinner(p,n);
delete p;
return 0;
}
void countWinner(TeamMember* p,int n)
{
map<int,int> m;
map<int,int>::iterator itor;
for(int i=0;i<n;i++)
{
itor=m.find(p[i].idOfTeam);
if(itor==m.end())
m.insert(pair<int,int>(p[i].idOfTeam,p[i].score));
else
itor->second+=p[i].score;
}
int maxIdOfTeam=0,maxScore=0;
for(itor=m.begin() ;itor!=m.end() ;itor++)
{
if(itor->second>maxScore)
{
maxIdOfTeam=itor->first;
maxScore=itor->second;
}
}
cout<<maxIdOfTeam<<" "<<maxScore;
}
标签:string max else using xid ima pair inner image
原文地址:https://www.cnblogs.com/FDProcess/p/9245758.html