skyark1214 @ 2022-05-01 19:56:33
#include<bits/stdc++.h>
using namespace std;
int num[303];
int sum[303];
int chh[303];
int main() {
int a;
cin>>a;
int ch,ma,en;
int cha,chb;
int chhua;
for(int i=0; i<a; ++i) {
cin>>chh[i]>>ma>>en;
sum[i]=chh[i]+ma+en;
num[i]=i+1;
}
for(int i=0; i<a-1; ++i) {
for(int j=0; j<a-i-1; ++j) {
if((sum[j]<sum[j+1]||((sum[j]==sum[j+1])&&(chh[j]<chh[j+1]))||(((sum[j]==sum[j+1])&&(chh[j]==chh[j+1]))&&(num[j]<num[j+1])))){
cha=sum[j];
sum[j]=sum[j+1];
sum[j+1]=cha;
chhua=chh[j];
chh[j]=chh[j+1];
chh[j+1]=chhua;
chb=num[j];
num[j]=num[j+1];
num[j+1]=chb;
}
}
}
for(int i=0; i<5; ++i) {
cout<<num[i]<<" "<<sum[i]<<endl;
}
return 0;
}
by metaphysis @ 2022-05-02 14:17:40
@skyark1214
如果只有
for(int i=0; i<5; ++i) {
cout<<num[i]<<" "<<sum[i]<<endl;
}
仍然会输出