文章

211

粉丝

1

获赞

1154

访问

47.1k

头像
学生成绩排序 - 西农 题解:
P5205 西北农林科技大学机试题
发布于2026年3月16日 09:38
阅读数 116

#include<bits/stdc++.h>
using namespace std;
struct node{
	string tag,name;
	int score;
};	
bool cmp(node a,node b){
	return a.score < b.score;
}	
bool rcmp(node a,node b){
	return a.score > b.score;
}
int main(){
	vector<node> a(5);
	for(int i=0;i<5;i++)
		cin >> a[i].tag >> a[i].name >> a[i].score;	
	sort(a.begin(),a.end(),cmp);
	for(auto it:a)
		cout << it.tag << " " << it.name << " " << it.score << endl;
	sort(a.begin(),a.end(),rcmp);
	for(auto it:a)
		cout << it.tag << " " << it.name << " " << it.score << endl;
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发