大一新生的一个解法
较为萌新
# include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main()
{
int N;
cin >> N;
struct team1
{
int score;
};
team1 team[10001] = { 0 };
char s[7];
int num=0;//记录-的位置
int num_team=0;//记录队伍的编号
int score1;//记录成绩
for (int i = 0; i < N; i++)
team[i].score = 0;
for (int i = 0; i < N; i++)//参赛队员
{
num_team = 0;//初始化
cin >> s;
for (int k = 0; k < 7; k++)
if (s[k] == '-')
{
num = k + 1;//-在从左往右数第k+1位
break;
}
for (int l = 0; l < num-1; l++)//计算队伍的编号
{
num_team += int(s[l]-'0') * pow(10, num - l - 2);
}
cin >> score1;
team[num_team].score += score1;
}
int max = team[0].score;
int max_team = 0;
for (int i = 0; i < 10001; i++)
{
if (team[i].score > max)
{
max = team[i].score;
max_team = i;
}
}
cout << max_team << " " << team[max_team].score;
return 0;
}