Langrange2021 @ 2022-09-17 17:20:23
#include <stdio.h>
#include <string.h>
struct test
{
char name[9];
int chin;
int math;
int eng;
};
int main()
{
int max=0;
int N;
scanf("%d", &N);
char na[9];
int ch=0;
int ma=0;
int en=0;
for (int k = 0; k < N; k++)
{
struct test store;
int sum;
scanf("%s", store.name);
scanf("%d%d%d", &store.chin, &store.math, &store.eng);
sum = store.chin + store.math + store.eng;
if (sum > max)
{
max = sum;
for (int q = 0; q < 9; q++)
{
if (store.name[q] == '\0')
{
break;
}
na[q] = store.name[q];
}
ch = store.chin;
ma = store.math;
en = store.eng;
}
}
for (int y = 0; y < 9; y++)
{
if (na[y] == '\0')
{
break;
}
printf("%c", na[y]);
}
printf(" ");
printf("%d %d %d", ch, ma, en);
return 0;
}
by Adchory @ 2022-09-17 17:45:18
@Langrange2021 把 Max
赋值为 string
赋值。可以自己去百度上看。
by 初星逝者 @ 2022-09-17 17:45:43
我真是服了,能不能用结构体排序啊
by 初星逝者 @ 2022-09-17 17:48:25
加个万能头和std,就可以直接
cout<<na;
了
by Adchory @ 2022-09-17 17:50:27
@初星逝者 cmp之后在学吧
by Adchory @ 2022-09-17 17:51:29
@Langrange2021 记录最大下标在输出
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string name[1005];
ll cg[1005],mg[1005],eg[1005],n,maxn=-999999,t;
int main(){
scanf("%lld",&n);
for(ll a=0;a<n;a++)
cin>>name[a]>>cg[a]>>mg[a]>>eg[a];
for(ll b=0;b<n;b++){
if(cg[b]+mg[b]+eg[b]>maxn){
maxn=cg[b]+mg[b]+eg[b];
t=b;
}
}
cout<<name[t]<<" "<<cg[t]<<" "<<mg[t]<<" "<<eg[t];
return 0;
}
by Langrange2021 @ 2022-09-17 17:58:14
@Reimu_Hakurei dl我用的是c语言
by 初星逝者 @ 2022-09-17 17:59:47
@Langrange2021 6,你学编程是干嘛的,不学c++?
by Adchory @ 2022-09-17 17:59:50
@Langrange2021 差不多,看思路就行了