标签:des style http color os java io strong for
/*
题目大意:按照EXCEL的要求排序
解题思路:用sort排序
难点详解:如何对字符排序,如何对数字排序
关键点:排序
解题人:lingnichong
解题时间:2014-08-09 17:19:36
解题体会:对理解和熟练运用sort排序,有很大的帮助
*/
3 1 000007 James 85 000010 Amy 90 000001 Zoe 60 4 2 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 98 4 3 000007 James 85 000010 Amy 90 000001 Zoe 60 000002 James 90 0 0
Case 1: 000001 Zoe 60 000007 James 85 000010 Amy 90 Case 2: 000010 Amy 90 000002 James 98 000007 James 85 000001 Zoe 60 Case 3: 000001 Zoe 60 000007 James 85 000002 James 90 000010 Amy 90
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct per { char number[20]; char name[20]; int grade; }st[100010]; int cmp1(per x,per y) { return strcmp(x.number,y.number)<0; } int cmp2(per x,per y) { if(strcmp(x.name,y.name)>0) return 0; else if(strcmp(x.name,y.name)==0) { return strcmp(x.number,y.number)<0; } return 1; } int cmp3(per x,per y) { if(x.grade>y.grade) return 0; else if(x.grade==y.grade) { return strcmp(x.number,y.number)<0; } return 1; } int main() { int n,c; int i,j,t=1; while(scanf("%d%d",&n,&c),(n!=0&&c!=0)) { for(i=0;i<n;i++) { scanf("%s%s%d",&st[i].number,&st[i].name,&st[i].grade); } printf("Case %d:\n",t++); if(c==1) sort(st,st+n,cmp1); if(c==2) sort(st,st+n,cmp2); if(c==3) sort(st,st+n,cmp3); for(i=0;i<n;i++) printf("%s %s %d\n",st[i].number,st[i].name,st[i].grade); } return 0; }
标签:des style http color os java io strong for
原文地址:http://blog.csdn.net/qq_16767427/article/details/38829171