AnOIer @ 2023-08-13 15:33:57
#include<bits/stdc++.h>
using namespace std;
int c,m,e,sum[1000];
int main(){
int n,ma=-100,k;
cin>>n;
for(int i=1;i<=n;i++){
cin>>c>>m>>e;
sum[i]=c+m+e;
}
for(int j=1;j<=5;j++){
ma=-100;
for(int i=1;i<=n;i++){
if(sum[i]>ma) {
ma=sum[i];
k=i;//更新下标
}
}
cout<<k<<" "<<ma<<endl;
sum[k]-=1000;
}
return 0;
}
by qi__ @ 2023-08-17 14:09:02
#include<bits/stdc++.h>
using namespace std;
struct cc
{
int all,a,b,c;
int num;
}g[301];
bool cmp(cc x,cc y)
{
if(x.all>y.all) return 1;
if(x.all==y.all)
{
if(x.a>y.a)
return 1;
if(x.a==y.a)
{
if(x.num<y.num)
return 1;
}
}
return 0;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>g[i].a>>g[i].b>>g[i].c;
g[i].num=i;
g[i].all=g[i].a+g[i].b+g[i].c;
}
sort(g+1,g+n+1,cmp);
for(int i=1;i<=5;i++)
cout<<g[i].num<<' '<<g[i].all<<endl;
}
by uzi_showmaker @ 2023-08-17 14:28:06
如果两个同学总分相同,再按语文成绩从高到低排序 qwq
#include<bits/stdc++.h>
using namespace std;
int c,m,e,sum[1005],chinese[1005];
int main(){
int n,ma=-100,k,mc;
cin>>n;
for(int i=1;i<=n;i++){
cin>>chinese[i]>>m>>e;
sum[i]=chinese[i]+m+e;
}
for(int j=1;j<=5;j++){
ma=-100,mc=-100;
for(int i=1;i<=n;i++){
if(sum[i]>ma) {
ma=sum[i];
mc=chinese[i];
k=i;//更新下标
}
else if(sum[i]==ma&&chinese[i]>mc)
{
mc=chinese[i];
k=i;
}
}
cout<<k<<" "<<ma<<endl;
sum[k]-=1000;
}
return 0;
}