HDU3293:sort
来源:互联网 发布:linux替换命令 编辑:程序博客网 时间:2024/06/02 05:44
Problem Description
As is known to all, long long ago sailormoon once was an association of fighters. Till now, sailormoon is also an association of girls. Owe to some unknown reasons, girls are necessary to fight for peace.
Their boss, lcy, wants to strengthen their ability, so he give them his precious collections---weapons for many years. Because these collections are really age-old, it is hard to recognize from one to another. So girls intend to sort them before they use. Each weapon has its name, origin and level of harmfulness ( level contains three ranks: wonderful, good, so-so).
In order to make it clear, girls want to sort like this:
firstly,sort according to the origin (sort by lexicographic order), if two or more have the same origin, they will be sorted together;
secondly, sort according ranks, wonderful is the best, good is next, the third is so-so;
thirdly, if two or more have same origin and rank, sort them according to the lexicographic order.
Their boss, lcy, wants to strengthen their ability, so he give them his precious collections---weapons for many years. Because these collections are really age-old, it is hard to recognize from one to another. So girls intend to sort them before they use. Each weapon has its name, origin and level of harmfulness ( level contains three ranks: wonderful, good, so-so).
In order to make it clear, girls want to sort like this:
firstly,sort according to the origin (sort by lexicographic order), if two or more have the same origin, they will be sorted together;
secondly, sort according ranks, wonderful is the best, good is next, the third is so-so;
thirdly, if two or more have same origin and rank, sort them according to the lexicographic order.
Input
Input contains multiply cases. Each case contains several lines. First line is an integer N(0<N<=500), representing the number of weapons. Then N lines follows. Each line represent a kind of weapon, and contains a set of strings representing name, origin and level of harmfulness.
Each string will not exceed 20 characters.
Sure that same origin will not exist the same weapon.
Each string will not exceed 20 characters.
Sure that same origin will not exist the same weapon.
Output
Please output your list after sorting (format according to sample, pay attention to the spaces,ten spaces need ^ ^).
Sample Input
5knife qizhou so-sogun qizhou wonderfulknife zhengzhou goodstick zhengzhou goodrope shengzhou so-so
Sample Output
Case 1qizhou: gun wonderful knife so-soshengzhou: rope so-sozhengzhou: knife good stick good
一道简单的结构体排序
排序优先级
1:按持有者名字
2:按武器级别
3:按武器名字
水题
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct NODE{ char name[30]; char lv[30]; char ori[30];} girl[505];int cmp(NODE x,NODE y){ if(strcmp(x.ori,y.ori)) return strcmp(x.ori,y.ori)<0; if(strcmp(x.lv,y.lv)) { if(!strcmp(x.lv,"wonderful")) return 1; if(!strcmp(y.lv,"wonderful")) return 0; if(!strcmp(y.lv,"so-so")) return 1; if(!strcmp(x.lv,"so-so")) return 0; } return strcmp(x.name,y.name)<0;}int main(){ int n,i,cas = 1; while(~scanf("%d",&n)) { for(i = 0; i<n; i++) scanf("%s%s%s",girl[i].name,girl[i].ori,girl[i].lv); printf("Case %d\n",cas++); sort(girl,girl+n,cmp); char s[30]; strcpy(s,girl[0].ori); int flag = 1; for(i = 0; i<n; i++) { if(flag) { printf("%s:\n",s); flag = 0; } printf(" %s %s\n",girl[i].name,girl[i].lv); if(strcmp(s,girl[i+1].ori)) { strcpy(s,girl[i+1].ori); flag = 1; } } } return 0;}
- HDU3293:sort
- HDU3293 sort 【排序】
- HDU3293-排序
- hdu3293(运用结构体)
- hdu3293(字符串排序)
- sort
- Sort
- sort
- Sort
- sort
- Sort
- sort
- sort
- Sort
- Sort
- sort
- sort
- sort
- 包和访问权限(1)
- Java编程思想--多态
- 找论文的好地方 http://www.soe.ucsc.edu/~you/notes/research-resources-ucsc.html
- 奇葩的公司,奇葩的现象……
- SNS网店API合作推广法
- HDU3293:sort
- static修饰的局部变量
- <长文本、一>SAP 通过SE75创建长文对象以及调用创建的对象操作方法介绍
- hdu 2608
- Android中shape的使用
- Nginx windows下搭建过程
- cells(11)
- [android]网络通信demo
- Android ScrollView HorizontalScrollView 实现全方向(上下左右)反弹效果