文章
19
粉丝
98
获赞
3
访问
10.4k
#include <bits/stdc++.h>
using namespace std;
struct student{
char name[20];
int grade;
int seq;
} ;
bool comp1(student lhs,student rhs)
{
if(lhs.grade<rhs.grade)
return true;
else if(lhs.grade==rhs.grade&&lhs.seq<rhs.seq)
return true;
else
return false;
}
bool comp0(student lhs,student rhs)
{
if(lhs.grade>rhs.grade)
return true;
else if(lhs.grade==rhs.grade&&lhs.seq<rhs.seq)
return true;
else
return false;
}
int main()
{ student stu [1000];
int num,i,n;
while(scanf("%d%d",&i,&n)!=EOF){
for (num=0;num<i;num++)
{
scanf("%s%d",&stu[num].name,&stu[num].grade);
stu[num].seq=num;
}
if(n==0) sort(stu,stu+i,comp0);
if(n==1) sort(stu,stu+i,comp1);
for(int b=0;b<i;b++)
{
printf("%s %d\n",stu[b].name,stu[b].grade);
}}
return 0;
}
登录后发布评论
暂无评论,来抢沙发