Forrest


私信TA

用户名:dotcpp0717441

访问量:3467

签 名:

等  级
排  名 89
经  验 9044
参赛次数 1
文章发表 120
年  龄 0
在职情况 教师
学  校 优学乐程
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

#include <iostream>
#include <algorithm>
using namespace std;
struct st{
	int sn,chinese, english, math, total;
};
const int N = 1e3 + 10;
st score[N];
bool cmp(st a, st b){
	if (a.total == b.total){
		if(a.chinese == b.chinese)
			return a.sn < b.sn;
		return a.chinese > b.chinese;
	}
	return a.total > b.total;
}
int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i ++) {
		score[i].sn = i + 1;
		cin >> score[i].chinese >> score[i].math >> score[i].english;
		score[i].total = score[i].chinese + score[i].math + score[i].english;
	}
	sort(score, score + n, cmp);
	for(int i = 0; i < 5; i ++){
		cout << score[i].sn << ' ' << score[i].total<< endl;
	}
	return 0;
}


 

0.0分

0 人评分

  评论区

  • «
  • »