7546391a @ 2022-12-04 23:00:42
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student {
int number;
int yuwen;
int shuxue;
int yingyu;
int sumer;
};
bool cmp(student& a, student& b)
{
if (a.sumer != b.sumer) return a.sumer > b.sumer;
else
{
if (a.yuwen != b.yuwen) return a.yuwen > b.yuwen;
else
{
return a.number < b.number;
}
}
}
const int N = 10010;
student arr[N];
int sum[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
arr[i].number = i;
cin >> arr[i].shuxue >> arr[i].yingyu >> arr[i].yuwen;
}
for (int i = 0; i < n; i++)
{
sum[i] = arr[i].shuxue + arr[i].yingyu + arr[i].yuwen;
arr[i].sumer = sum[i];
}
sort(arr, arr + n, cmp);
cout << -1 << endl;
for (int i = 0; i < 5; i++)
{
cout << arr[i].number + 1 << " " << arr[i].sumer;
cout << endl;
}
return 0;
}
by HopesandDreams @ 2022-12-05 08:11:31
@7546391a 我也不知道为什么你的写法会WA,但是好像 cmp 写的不太对。
//我的代码
#include <iostream>
#include <algorithm>
using namespace std;
struct peo{
int ch,ma,en;
int mark;
int id;
} a[305];
bool cmp(peo x,peo y){
if (x.mark > y.mark) return 1;
else if (x.mark < y.mark) return 0;
else{
if (x.ch > y.ch) return 1;
else if (x.ch < y.ch) return 0;
else{
if (x.id > y.ch) return 0;
else return 1;
}
}
}
int main(){
int n;
cin>>n;
for (int i = 1;i <= n;i++){
cin>>a[i].ch>>a[i].ma>>a[i].en;
a[i].mark = a[i].ch + a[i].ma + a[i].en;
a[i].id = i;
}
sort(a + 1,a + n + 1,cmp);
for (int i = 1;i <= 5;i++){
cout<<a[i].id<<" "<<a[i].mark<<endl;
}
}
by xlzg0707 @ 2022-12-11 11:51:50
#include<bits/stdc++.h>
using namespace std;
const int N=10010;
struct student {
int number,yuwen,shuxue,yingyu,sumer;
}arr[N];
bool cmp(student a, student b)
{
if(a.sumer!=b.sumer) return a.sumer>b.sumer;
else
{
if(a.yuwen!=b.yuwen) return a.yuwen>b.yuwen;
else
{
return a.number<b.number;
}
}
}
int sum[N];
int main()
{
int n;
cin>>n;
for (int i=0;i<n;i++)
{
arr[i].number=i;
cin>>arr[i].yuwen>>arr[i].shuxue>>arr[i].yingyu;
}
for(int i=0;i<n;i++)
{
sum[i]=arr[i].shuxue+arr[i].yingyu+arr[i].yuwen;
arr[i].sumer=sum[i];
}
sort(arr,arr+n,cmp);
for (int i=0;i<5;i++)
{
cout<<arr[i].number+1 <<" "<<arr[i].sumer<<endl;
}
return 0;
}
by xlzg0707 @ 2022-12-11 11:52:33
输入的时候语文和英语写反了
by ganxingyu @ 2022-12-20 13:49:26
@7546391a 这道题的排序还与语文成绩有关,具体再读题 你WA的两个点都与此有关