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

PAT 1028

2019-11-08 01:53:57
字体:
来源:转载
供稿:网友
#include<cstdio>#include<algorithm>#include<stdlib.h>#include<cstring>using namespace std;struct student{	int id;	char name[10];	int grade;}st[100010];int c;bool cmp(student x,student y){	if(c==1)			return x.id<y.id;	else if(c==2)	{		if(strcmp(x.name,y.name)!=0)			return strcmp(x.name,y.name)<0;		else 			return x.id<y.id;	}	else if(c==3)	{		if(x.grade!=y.grade)			return x.grade<y.grade;		else			return x.id<y.id;	}}int main(){	int n;	scanf("%d%d",&n,&c);	for(int i=0;i<n;i++)	{		scanf("%d %s %d",&st[i].id,st[i].name,&st[i].grade);	}	sort(st,st+n,cmp);	for(int i=0;i<n;i++)	{		PRintf("%06d %s %d/n",st[i].id,st[i].name,st[i].grade);	}	system("pause");	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表