zoj 2727 List the Books(三级排序 = =水题)
2011-01-19 14:38
761 查看
给书的名字,年份,价格排序。
名字优先级大于年份大于价格。
无语死了都 = =。用sort排序,返回值是0或者1,返回2都不行 = =。这个记住了。
名字优先级大于年份大于价格。
无语死了都 = =。用sort排序,返回值是0或者1,返回2都不行 = =。这个记住了。
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <algorithm> using namespace std; typedef struct{ char name[85]; int year,price; }book; book b[105]; int cmpname(book a,book b) { if( strcmp(a.name,b.name) == 0 ) if( a.year == b.year ) return a.price < b.price; else return a.year < b.year; if( strcmp(a.name,b.name) == -1 ) return 1; else return 0; } int cmpyear(book a,book b) { if( a.year == b.year ) if( strcmp(a.name,b.name) == 0 ) return a.price < b.price; else return cmpname(a,b); return a.year < b.year; } int cmpprice(book a,book b) { if( a.price == b.price ) if( strcmp(a.name,b.name) == 0 ) return a.year < b.year; else return cmpname(a,b); return a.price < b.price; } int main() { int n,i; char cmp[10]; int flag = 0; while( scanf("%d",&n)!=EOF && n ) { if( flag ) printf("/n"); flag = 1; for(i=0; i<n; i++) scanf("%s %d %d",b[i].name, &b[i].year,&b[i].price); scanf("%s",cmp); if( strcmp(cmp,"Price") == 0 ) sort(b,b+n,cmpprice); else if( strcmp(cmp,"Name") == 0 ) sort(b,b+n,cmpname); else sort(b,b+n,cmpyear); for(i=0; i<n; i++) printf("%s %d %d/n",b[i].name,b[i].year,b[i].price); } return 0; }
相关文章推荐
- zoj 2727 List the Books(排序)
- zoj 2727 List the Books
- zoj 2727 list the books
- ZOJ 2727 List the Books
- ZOJ List the Books 水~
- ZOJ List the Books 水~
- zoj 2727 List the Book
- ZOJ2727 List the Books
- UVA 11987 Where is the Marble? [排序水题]
- ZOJ - 3879 Capture the Flag (模拟)题意难懂的水题
- A list of books on general-purpose algorithms for the practical programmer (or 'software engineer')
- PAT甲题题解-1012. The Best Rank (25)-排序水题
- HDU 5500 Reorder the Books【水题】
- HDU1004 ZOJ2104 Let the Balloon Rise【MAP+水题】
- zoj 3809 The Himalayas 水题 The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
- 三级排序 qsort zoj 2727
- Codeforces Round #357 (Div. 2) D. Gifts by the List 水题
- ZOJ 3657 The Little Girl who Picks Mushrooms 第37届ACM/ICPC长春赛区现场赛C题(水题)
- ZOJ 3938 Defuse the Bomb(水题/细心模拟)
- ZOJ 3938 Defuse the Bomb(水题)