juchenglin @ 2023-03-30 21:26:59
#include<bits/stdc++.h>
using namespace std;
struct money
{
int zong, chinese, math, english, id;
}mon[305];
bool cmp(money a, money b)
{
if(a.zong != b.zong)
{
return a.zong > b.zong;
}
if(a.chinese != b.chinese)
{
return a.chinese > b.chinese;
}
return a.id > b.id;
}
int main()
{
int n;
cin >> n;
for(int i = 1 ; i <= n; i++)
{
cin >> mon[i].chinese >> mon[i].math >> mon[i].english;
mon[i].id = i;
mon[i].zong = mon[i].chinese + mon[i].math + mon[i].english;
}
sort(mon + 1, mon + n + 1, cmp);
for(int i = 1 ; i <= n ; i++)
{
cout << mon[i].id << mon[i].zong;
}
return 0;
}
by lingyuxuan666 @ 2023-03-30 21:36:56
前五名
by 2011Andy @ 2023-03-30 21:49:25
#include<bits/stdc++.h>
using namespace std;
struct money
{
int zong, chinese, math, english, id;
}mon[305];
bool cmp(money a, money b)
{
if(a.zong != b.zong)
{
return a.zong > b.zong;
}
if(a.chinese != b.chinese)
{
return a.chinese > b.chinese;
}
return a.id < b.id;
}
int main()
{
int n;
cin >> n;
for(int i = 1 ; i <= n; i++)
{
cin >> mon[i].chinese >> mon[i].math >> mon[i].english;
mon[i].id = i;
mon[i].zong = mon[i].chinese + mon[i].math + mon[i].english;
}
sort(mon + 1, mon + n + 1, cmp);
for(int i = 1 ; i <= 5 ; i++)
{
cout << mon[i].id << " " << mon[i].zong << endl;
}
return 0;
}
by zhc110803 @ 2023-04-09 22:22:24
只输出排序好的前五名的成绩
by wangyifan090531 @ 2023-04-27 19:21:28
#include<bits/stdc++.h>
using namespace std;
struct money
{
int zong, chinese, math, english, id;
}mon[305];
bool cmp(money a, money b)
{
if(a.zong != b.zong)
{
return a.zong > b.zong;
}
if(a.chinese != b.chinese)
{
return a.chinese > b.chinese;
}
if(a.id!=b.id)//改动1:未判断学号(也就是你写的id)
{
return a.id<b.id;
}
return a.id > b.id;
}
int main()
{
int n;
cin >> n;
for(int i = 1 ; i <= n; i++)
{
cin >> mon[i].chinese >> mon[i].math >> mon[i].english;
mon[i].id = i;
mon[i].zong = mon[i].chinese + mon[i].math + mon[i].english;
}
sort(mon + 1, mon + n + 1, cmp);
for(int i = 1 ; i <= 4 ; i++)
{
cout << mon[i].id <<" "<< mon[i].zong;
cout<<endl;
}
cout<<mon[5].id<<" "<<mon[5].zong;//改动2:只输出5个
return 0;
}
//wangyifan090531