hdu 3293 sort
2015-08-13 12:28
381 查看
hdu 3293 sort
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 752 Accepted Submission(s): 355
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.
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.
Output
Please output your list after sorting (format according to sample, pay attention to the spaces,ten spaces need ^ ^).
Sample Input
Sample Output
按照来源(origin)、等级(rank)、武器(weapons)的先后顺序排序,然后按要求输出。
题目:
sort
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 752 Accepted Submission(s): 355
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.
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.
Output
Please output your list after sorting (format according to sample, pay attention to the spaces,ten spaces need ^ ^).
Sample Input
5 knife qizhou so-so gun qizhou wonderful knife zhengzhou good stick zhengzhou good rope shengzhou so-so
Sample Output
Case 1 qizhou: gun wonderful knife so-so shengzhou: rope so-so zhengzhou: knife good stick good
题意:
简单的排序题,输出有些麻烦,可以用哈希做,效果一样,排序算法可以调用系统库函数,也可以自己手写。按照来源(origin)、等级(rank)、武器(weapons)的先后顺序排序,然后按要求输出。
代码:
#include<stdio.h> #include<string.h> char smap[3][20]= {"wonderful","good","so-so"}; struct node { char origin[51]; char weapons[51]; int ranks; }; int to_int(char *p) { int i; for(i=0; i<3; i++) if(strcmp(p,smap[i])==0) break; return i; } void mysort(node * wo,int len) { int i,k,j; node temp; for(i=0; i<len; i++) { k=i; for(j=i; j<len; j++) { if(strcmp(wo[k].origin,wo[j].origin)==0) { if(wo[k].ranks==wo[j].ranks) { if(strcmp(wo[k].weapons,wo[j].weapons)>0) k=j; } else if(wo[k].ranks>wo[j].ranks) k=j; } else if(strcmp(wo[k].origin,wo[j].origin)>0) k=j; } if(k!=i) { temp=wo[i]; wo[i]=wo[k]; wo[k]=temp; } } } int main() { int n,flag,i,tt=1; struct node wo[501]; char s[51]; while(scanf("%d\n",&n)!=EOF) { for(i=0; i<n; i++) { scanf("%s %s %s",wo[i].weapons,wo[i].origin,s); wo[i].ranks=to_int(s); } mysort(wo,n); strcpy(s,wo[0].origin); flag=1; printf("Case %d\n",tt++); for(i=0;i<n;i++) { if(flag==1) { printf("%s:\n",s); flag=0; } printf(" %s %s\n",wo[i].weapons,smap[wo[i].ranks]); if(strcmp(s,wo[i+1].origin)) { strcpy(s,wo[i+1].origin); flag=1; } } } return 0; }
相关文章推荐
- 服务器优化:提高吞吐量,给主机加油
- Dark roads 2988
- MongoDB简单操作指令
- Python笔记:wsgi简介
- C语言strncpy()函数
- 解决SwipeRefreshLayout多重嵌套产生滑动冲突
- Android事件总线框架Otto使用
- js事件重复绑定问题
- 借助Net-Speeder对服务器进行优化
- MyEclipse web项目导入Eclipse,详细说明
- js实现文本框宽度自适应文本宽度的方法
- 线程间操作无效: 从不是创建控件“textBox2”的线程访问它
- CSS中 @media screen 和@media only screen 和@media 的不同
- 添加第三方库出现library not found for - "解决办法
- mysql多实例(多个配置文件方式)
- There are no devices installed for the specified ADAPTORNAME
- cheat engine lua
- fibonacci(n<=45)
- 一个phonegap门外汉的phonegap初体验
- 一个phonegap门外汉的phonegap初体验