当前位置: 代码迷 >> 综合 >> PAT A1028. List Sorting
  详细解决方案

PAT A1028. List Sorting

热度:56   发布时间:2023-11-20 23:35:16.0

这题简单

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct Student
{int id;char name[10];int grade;
}student[100010];bool cmp1(Student a,Student b)
{return a.id<b.id;
}bool cmp2(Student a,Student b)
{if(strcmp(a.name,b.name)!=0) return strcmp(a.name,b.name)<0;else return a.id<b.id;
}bool cmp3(Student a,Student b)
{if(a.grade!=b.grade) return a.grade<b.grade;else return a.id<b.id;
}int main()
{int N,C;scanf("%d %d",&N,&C);for(int i = 0;i<N;i++){scanf("%d %s %d",&student[i].id,student[i].name,&student[i].grade);}if(C==1){sort(student,student+N,cmp1);for(int i =0;i<N;i++){printf("%06d %s %d\n",student[i].id,student[i].name,student[i].grade);}}if(C==2){sort(student,student+N,cmp2);for(int i =0;i<N;i++){printf("%06d %s %d\n",student[i].id,student[i].name,student[i].grade);}}if(C==3){sort(student,student+N,cmp3);for(int i =0;i<N;i++){printf("%06d %s %d\n",student[i].id,student[i].name,student[i].grade);}}return 0;
}

 

  相关解决方案