danaqi_ @ 2023-09-09 11:53:12
代码可能有些乱,请谅解
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
struct node{
int x,y,z;
int sum=0;
int ss;
}a[400];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
a[i].sum=a[i].x+a[i].y+a[i].z;
a[i].ss=i;
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n-i;++j){
if(a[j].sum<a[j+1].sum)
swap(a[j],a[j+1]);
else if(a[j].sum==a[j+1].sum){
if(a[j].x<a[j+1].x){
swap(a[j],a[j+1]);
break;
}
if(a[j].x==a[j+1].x){
if(a[j].ss>a[j].ss)
swap(a[j],a[j+1]);
}
}
}
}
for(int i=1;i<=5&&i<=n;++i)
printf("%d %d\n",a[i].ss,a[i].sum);
return 0;
}
by wangjiayuan @ 2023-09-09 12:25:46
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
struct node{
int x,y,z;
int sum=0;
int ss;
}a[400];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
a[i].sum=a[i].x+a[i].y+a[i].z;
a[i].ss=i;
}
for(int i=1;i<=n;++i){
for(int j=1;j<=n-i;++j){
if(a[j].sum<a[j+1].sum)
swap(a[j],a[j+1]);
else if(a[j].sum==a[j+1].sum){
if(a[j].x<a[j+1].x){
swap(a[j],a[j+1]);
}
if(a[j].x==a[j+1].x){
if(a[j].ss>a[j].ss)
swap(a[j],a[j+1]);
}
}
}
}
for(int i=1;i<=5;++i)
printf("%d %d\n",a[i].ss,a[i].sum);
return 0;
}
点个关注谢谢喵~
by unhappysheep @ 2023-09-09 17:13:44
@danaqi 多日不见
by danaqi_ @ 2023-09-10 14:29:52
@unhappysheep
你个鸡 ~
鸽鸽.jpg
by unhappysheep @ 2023-09-10 17:06:36
@danaqi_ 你什莫意思啊
by danaqi_ @ 2023-09-11 21:03:51
@unhappysheep
难道!!你不是坤家军?!
by unhappysheep @ 2023-09-12 07:58:05
@danaqi_ 999