XDuanZai @ 2024-10-08 16:16:53
0pts
#include<iostream>
using namespace std;
int a[10005],n,x,y,z,maxn=-1,s=0,k[10005],b[10005];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>x>>y>>z,a[i]=x+y+z,k[i]=x,b[i]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i]<a[i+1]){
swap(a[i],a[i+1]);
swap(k[i],k[i+1]);
swap(b[i],b[i+1]);
}else if(a[i]==a[i+1]){
if(k[i]<k[i+1]){
swap(a[i],a[i+1]);
swap(k[i],k[i+1]);
swap(b[i],b[i+1]);
}
}
}
}
for(int i=1;i<=5;i++) cout<<b[i]<<' '<<a[i]<<endl;
return 0;
}
by craftmine @ 2024-10-08 17:08:03
你是WA还是TLE?
by craftmine @ 2024-10-08 17:11:56
冒泡是用j来排的,不是i
#include<iostream>
using namespace std;
int a[10005],n,x,y,z,maxn=-1,s=0,k[10005],b[10005];
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>x>>y>>z,a[i]=x+y+z,k[i]=x,b[i]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[j]<a[j+1]){
swap(a[j],a[j+1]);
swap(k[j],k[j+1]);
swap(b[j],b[j+1]);
}else if(a[j]==a[j+1]){
if(k[j]<k[j+1]){
swap(a[j],a[j+1]);
swap(k[j],k[j+1]);
swap(b[j],b[j+1]);
}
}
}
}
for(int i=1;i<=5;i++) cout<<b[i]<<' '<<a[i]<<endl;
return 0;
}
by craftmine @ 2024-10-08 17:25:02
@XDuanZai
by craftmine @ 2024-10-08 17:25:24
我下线了
by XDuanZai @ 2024-10-09 18:02:43
@craftmine Thank You!!!