文章

64

粉丝

53

获赞

3

访问

15.8k

头像
成绩排序2.0 题解:
P1159 清华大学上机题
发布于2024年3月17日 20:41
阅读数 180

1159解题思路:使用stable_sort()和结构体实现排序;先对学号排序,后对成绩排序;

#include <bits/stdc++.h>
 using namespace std;
 struct Student{
 	int num;
 	double pride;
 }stu[105];
 bool array_DSC(Student a,Student b)
 {
 	return a.pride<b.pride;
  } 
  bool a_ASC(Student a,Student b)
  {
  	return a.num<b.num;
  }
 int main()
 {
 	int n;
 	while(cin>>n)
 	{
 		for(int i=0;i<n;i++)
 		{
 			scanf("%d %lld",&stu[i].num,&stu[i].pride);
		 }
		stable_sort(stu,stu+n,a_ASC);
		stable_sort(stu,stu+n,array_DSC);
		
		for(int i=0;i<n;i++)
		{
			printf("%d %lld\n",stu[i].num,stu[i].pride);
		}
	 }
 }

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发