标签:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; struct node { char num[7]; char name[9]; int score; }stu[100005]; bool cmp1(const node &a,const node &b) { if(strcmp(a.num,b.num)<0) return true; else return false; } bool cmp2(const node &a,const node &b) { if(strcmp(a.name,b.name)>0) return false; if(strcmp(a.name,b.name)==0) { if(strcmp(a.num,b.num)<0) return true; else return false; } if(strcmp(a.name,b.name)<0) return true; } bool cmp3(const node &a,const node &b) { if(a.score<b.score) return true; if(a.score==b.score) { if(strcmp(a.num,b.num)<0) return true; else return false; } if(a.score>b.score) return false; } int main() { int n,m,cnt; cnt=0; while(cin>>n>>m) { if(n==0&&m==0) break; for(int i=0;i<n;i++) { cin>>stu[i].num>>stu[i].name>>stu[i].score; } cnt++; if(m==1) sort(stu,stu+n,cmp1); if(m==2) sort(stu,stu+n,cmp2); if(m==3) sort(stu,stu+n,cmp3); printf("Case %d:\n",cnt); for(int i=0;i<n;i++) cout<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].score<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/nefu929831238/p/5325976.html