Mr_Pang @ 2023-12-12 17:39:26
#include<stdio.h>
int main()
{
struct Student
{
char name[100];
int chinese;
int math;
int english;
};
struct Student a[1001];
int N, i,sum,j=0;
int max = 0;
scanf("%d", &N);
for (i = 1; i <= N; i++)
{
scanf("%s%d%d%d", a[i].name, &a[i].chinese, &a[i].math, &a[i].english);
sum = a[i].chinese + a[i].math + a[i].english;
if (sum > max)
{
max = sum;
j = i;
}
}
printf("%s %d %d %d", a[j].name, a[j].chinese, a[j].math, a[j].english);
return 0;
}
显示我有一个答案错误,求助大家怎么改QAQ
by bycwxbd @ 2023-12-12 17:51:42
如果总分为0怎么办,所以max=-1
by bycwxbd @ 2023-12-12 17:52:20
@Mr_Pang
by gaoyunxuan0917 @ 2023-12-15 12:36:04
#include <bits/stdc++.h>
using namespace std;
struct s{
string name;
int yw, sx, yy;
}student[1001];
int main(){
int n, maxn=0, maxi=1;
cin >> n;
for (int i = 1;i <= n;i ++) {
cin >> student[i].name >> student[i].yw >> student[i].sx >> student[i].yy;
}
for (int i = 1;i <= n;i ++) {
if (student[i].yw+student[i].sx+student[i].yy>maxn) {
maxn = student[i].yw + student[i].sx + student[i].yy;
maxi = i;
}
}
cout << student[maxi].name << ' ' << student[maxi].yw << ' ' << student[maxi].sx << ' ' << student[maxi].yy;
}
by Mr_Pang @ 2023-12-17 19:25:45
@bycwxbd 非常感谢!!
by Mr_Pang @ 2023-12-17 19:26:04
@gaoyunxuan917 谢谢大佬!!
by gaoyunxuan0917 @ 2023-12-18 12:50:38
@Mr_Pang 不用谢,祝你早日成为神犇!