costudy @ 2024-02-01 20:01:33
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
struct student
{
char na[9];
int m,c,e,t;
}b[1001];
for(int i=0;i<n;i++)
{
cin>>b[i].na>>b[i].m>>b[i].c>>b[i].e;
b[i].t=b[i].c+b[i].m+b[i].e;
}
int max=-1,w;
for(int i=0;i<n;i++)
{
if(b[i].t<max)
{
max=b[i].t;
w=i;
}
}
cout<<b[w].na<<" "<<b[w].c<<" "<<b[w].e<<" "<<b[w].t;
return 0;
}
by wangtairan114 @ 2024-02-01 20:13:08
#include<bits/stdc++.h>
using namespace std;
struct student
{
string na;
int m,c,e,t;
}b[1001];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>b[i].na>>b[i].m>>b[i].c>>b[i].e;
b[i].t=b[i].c+b[i].m+b[i].e;
}
int max=-1,w;
for(int i=0;i<n;i++)
{
if(b[i].t>max)
{
max=b[i].t;
w=i;
}
}
cout<<b[w].na<<" "<<b[w].m<<" "<<b[w].c<<" "<<b[w].e;
return 0;
}
by yucheng0630 @ 2024-02-01 20:15:50
@costudy
结构体排序
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
struct stu{
string name;
int yw;
int sx;
int yy;
int zf;
int id;
};
bool cmp(stu x,stu y){
if(x.zf==y.zf){
if(x.id>y.id){
return 0;
}
else{
return 1;
}
}
if(x.zf>y.zf){
return 1;
}else{
return 0;
}
}
int main(){
int n;
stu a[maxn];
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].yw>>a[i].sx>>a[i].yy;
a[i].zf=a[i].yw+a[i].sx+a[i].yy;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=1;i++){
cout<<a[i].name<<" "<<a[i].yw<<" "<<a[i].sx<<" "<<a[i].yy;
}
return 0;
}
by costudy @ 2024-02-01 20:27:18
@wangtairan114 @yucheng0630 谢谢谢谢,各位幸苦了!