杭电hdu 1862 EXCEL排序 qsort
2012-05-07 18:58
423 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1862
简单的qsort二级排序
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; typedef struct _excel { char no[7]; char name[9]; int score; }excel; excel ex[100001]; int cmpno(const void *a, const void *b) { excel *fa = (excel*)a; excel *fb = (excel*)b; return strcmp(fa->no, fb->no) > 0 ? 1 : -1; } int cmpname(const void *a, const void *b) { excel *fa = (excel *)a; excel *fb = (excel *)b; if(strcmp(fa->name, fb->name)!=0)return strcmp(fa->name, fb->name) > 0 ? 1 : -1; return strcmp(fa->no, fb->no) > 0 ? 1 : -1; } int cmpscore(const void *a, const void *b) { excel *fa = (excel *)a; excel *fb = (excel *)b; if(fa->score != fb->score)return fa->score - fb->score > 0 ? 1 : -1; return strcmp(fa->no, fb->no) > 0 ? 1 : -1; } int main() { // freopen("input.in", "r", stdin); int n, i, hw; int cas = 1; while(scanf("%d%d", &n, &hw)&&n){ for(i = 0; i < n; i ++){ scanf("%s%s%d", ex[i].no, ex[i].name, &ex[i].score); } if(hw == 1){ qsort(ex, n, sizeof(ex[0]), cmpno); } else if(hw == 2){ qsort(ex, n, sizeof(ex[0]), cmpname); } else if(hw == 3){ qsort(ex, n, sizeof(ex[0]), cmpscore); } printf("Case %d:\n", cas ++); for(i = 0; i < n; i ++){ printf("%s %s %d\n", ex[i].no, ex[i].name, ex[i].score); } } return 0; }
相关文章推荐
- HDU-1862-EXCEL排序
- EXCEL排序 HDU - 1862
- HDU 1862 EXCEL次序 (排序水问题)
- 【杭电-oj】-1862-EXCEL排序(结构体)
- HDU 1862-EXCEL排序
- 杭电1862 EXCEL排序
- 杭电--1862--EXCEL排序--结构体排序
- 杭电OJ(HDOJ)1862题:EXCEL排序(结构体sort)
- hdu 1862 EXCEL排序
- 【ACM】hdu_1862_EXCEL排序_201308091948
- 杭电 1862 EXCEL排序
- 初试结构体杭电1862EXCEL排序
- HDU 1862 EXCEL排序(结构体排序)
- 寒假训练三A - EXCEL排序 HDU - 1862
- hdu(1862)EXCEL排序
- 【hdu 1862】EXCEL排序 (sort &结构体)
- HDU 1862 EXCEL排序 (排序水题)
- 【杭电】[1862]EXCEL排序
- 杭电1862EXCEL排序
- (九度oj亦有)HDU 1862 EXCEL排序