文章

34

粉丝

0

获赞

6

访问

1.0k

头像
成绩排序2.0 题解:
P1159 清华大学上机题
发布于2025年8月6日 16:28
阅读数 35

#include<bits/stdc++.h>
using namespace std;

struct Student{
	int id;
	int grade;
}stu[105];

bool cmp(Student a, Student b){
	if(a.grade == b.grade) return a.id < b.id;
	else return a.grade < b.grade;
}

int main(){
	
	int n; cin >> n;
	int cnt = n;
	while(n --){
		cin >> stu[n].id >> stu[n].grade;
	}
	
	sort(stu, stu+cnt, cmp);
	
	for(int i = 0; i < cnt; i++){
		cout << stu[i].id << " " << stu[i].grade << endl;
	}
	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发