文章

55

粉丝

57

获赞

11

访问

10.3k

头像
成绩排序 - 华科 题解:c++利用sort函数实现
P1404 华中科技大学
发布于2024年3月18日 01:23
阅读数 195

#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;

struct student{
	string name;
	int age;
	float score;
};

bool cmp(student a, student b){
	if(a.score != b.score){
		return a.score < b.score;
	}else if(a.name != b.name){
		return a.name < b.name;
	}else{
		return a.age < b.age;
	}
}

int main(){
	int n;
	while(cin>>n){
		struct student stu[1000];
		for(int i = 0; i<n; i++){
			cin>>stu[i].name>>stu[i].age>>stu[i].score;
		}
		sort(stu,stu+n,cmp);
		for(int i = 0; i<n; i++){
			cout<<stu[i].name<<" "<<stu[i].age<<" "<<stu[i].score<<endl;
		}
	}
}
 
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发