litianyu9 @ 2024-07-14 20:50:41
#include<iostream>
#include<algorithm>
using namespace std;
int a[350];
int c[350];
int top[6];
int cmp(int x,int y){
return x>y;
}
int main(){
int num,score,i,j,l,d,num1,total;
total=0;
cin>>num;
for(i=1;i<=num;i++){
total=0;
for(j=1;j<=3;j++){
cin>>score;
total+=score;
}
a[i]=total;
c[i]=total;
}
sort(a+1,a+1+num,cmp);
for(l=1;l<=5;l++){
num1=0;
for(d=1;d<=num;d++){
if(c[d]==a[l]){
if(top[l-1]!=d){
top[l]=d;
break;
} }
}
}
for(i=1;i<=5;i++){
cout<<top[i]<<" "<<a[i]<<endl;
}
return 0;
}
为啥只有70分
by xuruizhe0711 @ 2024-07-15 17:31:31
#include<bits/stdc++.h>
using namespace std;
struct student{
int name;
int china;
int math;
int english;
int score;
}a[305];
bool cmp(student a,student b){
if(a.score!=b.score){
return a.score>b.score;
}
else if(a.china!=b.china){
return a.china>b.china;
}
return a.name<b.name;
}
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].china>>a[i].math>>a[i].english;
a[i].score=a[i].china+a[i].math+a[i].english;
a[i].name=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].name<<" "<<a[i].score<<endl;
}
return 0;
}
by wangtianhao0609 @ 2024-08-01 13:10:24
#include<bits/stdc++.h>
using namespace std;
int n;
struct mystruct{
int maths,chinese,english,both,number;
};
mystruct a[301];
bool cmp(mystruct a,mystruct b){
if (a.both!=b.both)
{
return a.both>b.both;
}
else
if (a.chinese!=b.chinese)
{
return a.chinese>b.chinese;
}
else
{
return a.number<b.number;
}
}
int main(){
cin >>n;
for (int i=1;i<=n;i++)
{
cin >>a[i].chinese>>a[i].maths>>a[i].english;
a[i].both=a[i].chinese+a[i].maths+a[i].english;
a[i].number=i;
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=5;i++)
{
cout <<a[i].number<<" "<<a[i].both;
if (i!=5)
{
cout <<"\n";
}
}
return 0;
}