Rules for Programming Team: Each team composed of several members; all members of the independent game; teams score of all the players and the results; the highest team score wins.
Now given all the players race results, you write a program to find the winning team.
Input formats:
The first input line is given a positive integer N (≤104), i.e., the total number of all team members. Then N rows, each player is given a score, the format is: 队伍编号-队员编号 成绩
where 队伍编号
is a positive integer of 1 to 1,000, 队员编号
is a positive integer from 1 to 10, 成绩
an integer of 0 to 100.
Output formats:
Output championship team number and total score in a row, during which separated by a space. Note: The title winning team is the only guarantee.
Sample input:
6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61
Sample output:
11 176
Thinking
- The team regarded as the array index number, then read out the corresponding players on the increase in the corresponding position on the final traverse to find the maximum fine
Code
#include<bits/stdc++.h>
using namespace std;
int score_sum[1010] = {0};
int main()
{
int n;
scanf("%d", &n);
int team,id;
int score;
for(int i=0;i<n;i++)
{
scanf("%d-%d %d", &team, &id, &score);
score_sum[team] += score;
}
int max_team = -1;
int max_score = -1;
for(int i=1;i<=1000;i++)
{
if(score_sum[i] > max_score)
{
max_score = score_sum[i];
max_team = i;
}
}
cout << max_team << " " << max_score;
return 0;
}
Quote
https://pintia.cn/problem-sets/994805260223102976/problems/994805277163896832