1047 Programming Team Competition (20 points)
The rules of the programming team competition are: each team consists of several players; all players compete independently; the team's score is the sum of the scores of all players; the team with the highest score wins.
Now given the game scores of all players, please write a program to find out the champion team.
Input format:
Enter the first line to give a positive integer N (≤104), which is the total number of all participating players. Next N lines, each line gives the score of a player in the format: 队伍编号-队员编号 成绩
, which 队伍编号
is a positive integer from 1 to 1000, a positive integer 队员编号
from 1 to 10, and an integer 成绩
from 0 to 100.
Output format:
Print the number and total score of the champion team on one line, separated by a space. Note: The title guarantees that the champion team is unique.
Input sample:
6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61
Sample output:
11 176
#include<iostream>
#include<string>
using namespace std;
int main() {
int n, team[1050] = { 0 }, score;
cin >> n;
string s;
for (int i = 0; i < n; i++) {
cin >> s >> score;
int num = 0;
for (int j = 0; j < s.length() && s[j] != '-'; j++) {
num = num * 10 + s[j] - '0';
}
team[num] += score;
}
int x, y = -1;
for (int i = 0; i < 1050; i++) {
if (team[i] > y) {
x = i;
y = team[i];
}
}
cout << x << " " << y << endl;
return 0;
}