1 #include<iostream> 2 #include<algorithm> 3 #include<string.h> 4 using namespace std; 5 struct E 6 { 7 char id[7]; 8 char name[9]; 9 int score; 10 }e[100005]; 11 bool cmp1(E a,E b) 12 { 13 int temp=strcmp(a.id,b.id); 14 return temp<0; 15 } 16 bool cmp2(E a,E b) 17 { 18 int temp=strcmp(a.name,b.name); 19 return temp<0; 20 } 21 bool cmp3(E a,E b) 22 { 23 int temp=strcmp(a.id,b.id); 24 if(a.score!=b.score) return a.score<b.score; 25 else return temp<0; 26 } 27 int main() 28 { 29 int n,c; 30 while(cin>>n&&n) 31 { 32 cin>>c; 33 for(int i=0;i<n;i++) 34 { 35 cin>>e[i].id>>e[i].name>>e[i].score; 36 } 37 if(c==1) sort(e,e+n,cmp1); 38 if(c==2) sort(e,e+n,cmp2); 39 if(c==3) sort(e,e+n,cmp3); 40 cout<<"Case:"<<endl; 41 for(int i=0;i<n;i++) 42 { 43 cout<<e[i].id<<" "<<e[i].name<<" "<<e[i].score<<endl; 44 } 45 } 46 return 0; 47 } View Code
转载于:https://www.cnblogs.com/qing123tian/p/11153399.html
相关资源:王道2020考研笔试全集+机试指南.zip