首页 > 学院 > 开发设计 > 正文

1028

2019-11-14 10:02:16
字体:
来源:转载
供稿:网友
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct Student{	char id[10];	char name[10];	int grade;}stu[100010];bool cmp1(Student a, Student b){	return strcmp(a.id, b.id) < 0;}bool cmp2(Student a, Student b){	if (strcmp(a.name, b.name) != 0)		return strcmp(a.name, b.name) < 0;	else		return strcmp(a.id, b.id) < 0;}bool cmp3(Student a, Student b){	if (a.grade != b.grade)		return a.grade < b.grade;	else		return strcmp(a.id, b.id) < 0;}int main(){	int n, c;	scanf("%d%d", &n, &c);	for (int i = 0; i < n; i++){		scanf("%s %s %d", stu[i].id, stu[i].name, &stu[i].grade);	}	switch (c)	{	case 1:		sort(stu, stu + n, cmp1);		break;	case 2:		sort(stu, stu + n, cmp2);		break;	default:		sort(stu, stu + n, cmp3);		break;	}	for (int i = 0; i < n; i++){		PRintf("%s %s %d/n", stu[i].id, stu[i].name, stu[i].grade);	}	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表