jkluio1 @ 2024-03-30 17:15:11
#include<iostream>
#include<cstring>
using namespace std;
typedef struct stu{
string name;
int score[3];
int sum=0;
struct stu* next;
}*Std,stu;
int Init(Std& L);
int Init(Std& L)
{
L = new stu;
if (!L)
exit(0);
L->next = NULL;
return 1;
}
int input(Std &L, int n)
{
Std p1=new stu, p2=L;
if (!p1) exit(0);
for (int i = 0; i < n; i++)
{
cin >> p1->name;
for (int j = 0; j < 3; j++)
{
cin >> p1->score[j];
p1->sum += p1->score[j];
}
p2->next = p1;
p2 = p1;
p2->next = NULL;
p1 = new stu;
}
return 1;
}
stu compare(Std &L, int n)
{
stu max;
Std p1 = L->next;
max.name=p1->name;
max.score[0] = p1->score[0];
max.score[1] = p1->score[1];
max.score[2] = p1->score[2];
max.sum = 0;
p1 = p1->next;
int i =1;
while (i<n)
{
if(p1->sum > max.sum)
{
max.sum = p1->sum;
for(int j=0;j<3;j++)
max.score[j] = p1->score[j];
max.name = p1->name;
}
i++;
p1 = p1->next;
}
return max;
}
int main()
{
Std L; int n; stu max;
cin >> n;
Init(L);
input(L, n);
max=compare(L, n);
cout << max.name << ' ' << max.score[0]<<' '<< max.score[1]<<' '<< max.score[2];
return 0;
}
救命,过不了90;测试点7一直过不了
by sll00 @ 2024-04-03 16:49:39
@jkluio1 没看懂。。为什么不直接用结构体输入然后相加sum直接找到最大输出?
by jkluio1 @ 2024-04-04 15:15:58
@sll00 好的,谢谢,你这个方便多了好像,我试试,谢谢你