7-37 模拟EXCEL排序 (25 分)

排序入门题

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
struct stu{
	int no;
	char name[10];
	int score;	
}Node[maxn];
bool cmp1(stu a, stu b){
	return a.no <b.no;
}

bool cmp2(stu a, stu b){
	if(strcmp(a.name,b.name) != 0)
		return strcmp(a.name,b.name)<0;
	else 
		return a.no <b.no;
}

bool cmp3(stu a, stu b){
	if(a.score != b.score)
		return a.score < b.score;
	else 
		return a.no <b.no;
}
int main(){
	int n,c;
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++){
		scanf("%d%s%d",&Node[i].no,Node[i].name,&Node[i].score);
	}
	if(c==1){
		sort(Node,Node+n,cmp1);
	}else if(c==2){
		sort(Node,Node+n,cmp2);
	}else{
		sort(Node,Node+n,cmp3);
	}
	for(int i=0;i<n;i++){
		printf("%06d %s %d\n",Node[i].no,Node[i].name,Node[i].score);
	}
	return 0;
} 
全部评论

相关推荐

不对是145个人…嗯…&nbsp;大家都没发现秋招提前批来了嘛..笑死我了
牛客39712426...:投了也是浪费时间,之前投米实习,除了浪费我时间写笔试题没有任何反馈,懒得投了
26届校招投递进展
点赞 评论 收藏
分享
07-18 14:34
门头沟学院 Java
感觉招聘要求好高,这都是招什么人才
电气电子小朋友:你都说了这是大疆,无人机顶级企业,薪资30k-50k,要求高是正常的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务