PRoblem Link:http://139.129.36.234/problem.php?id=1209
3 1000007 James 85000010 Amy 90000001 Zoe 604 2000007 James 85000010 Amy 90000001 Zoe 60000002 James 984 3000007 James 85000010 Amy 90000001 Zoe 60000002 James 900 0样例输出
Case 1:000001 Zoe 60000007 James 85000010 Amy 90Case 2:000010 Amy 90000002 James 98000007 James 85000001 Zoe 60Case 3:000001 Zoe 60000007 James 85000002 James 90000010 Amy 90提示
来源
2007年浙江大学计算机及软件工程研究生机试真题
AC code:
#include<iostream>#include<algorithm>#include<stdio.h>#include<map>#include<math.h>#include<string.h>#include<queue>#include<vector>#include<set>#define LL long long#define exp 1e-9#define MAXN 1000010using namespace std;struct node{ string ID; string name; int score;}stu[100010];bool cmp1(node a,node b){ return a.ID<b.ID;}bool cmp2(node a,node b){ if(a.name != b.name) return a.name < b.name; else return a.ID < b.ID;}bool cmp3(node a,node b){ if(a.score != b.score) return a.score < b.score; else return a.ID < b.ID;}int main(){// freopen("D://in.txt","r",stdin); int n,c,i,T; T=0; while(scanf("%d %d",&n,&c)!=EOF) { T++; for(i=0;i<n;i++) { cin>>stu[i].ID>>stu[i].name>>stu[i].score; } if(c==1) { sort(stu,stu+n,cmp1); printf("Case %d:/n",T); for(i=0;i<n;i++) { cout<<stu[i].ID<<" "<<stu[i].name<<" "<<stu[i].score<<endl; } } else if(c==2) { sort(stu,stu+n,cmp2); printf("Case %d:/n",T); for(i=0;i<n;i++) { cout<<stu[i].ID<<" "<<stu[i].name<<" "<<stu[i].score<<endl; } } else if(c==3) { sort(stu,stu+n,cmp3); printf("Case %d:/n",T); for(i=0;i<n;i++) { cout<<stu[i].ID<<" "<<stu[i].name<<" "<<stu[i].score<<endl; } } } return 0;}
新闻热点
疑难解答