HDU 3293:sort
来源:互联网 发布:淘宝封号能自动解封吗 编辑:程序博客网 时间:2024/06/11 11:33
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
题目很清晰,先按来源地排序,然后排武器,最后是武器威力。就是排序算法!
直接上代码:
#include <iostream>#include <algorithm>#include <string.h>using namespace std;struct sa{ char a[25]; char b[25]; int c;}str[550];char k[3][20]={"so-so","good","wonderful"};int l=1;int cmp(const sa &p,const sa &q){ if(strcmp(p.b,q.b)!=0) return strcmp(p.b,q.b)<0; else if(p.c!=q.c) return p.c>q.c; else return strcmp(p.a,q.a)<0;}int main(){ int n; while(cin>>n) { char tmp[25]; for(int i=0;i<n;i++) { cin>>str[i].a>>str[i].b; cin>>tmp; if(strcmp(tmp,"so-so")==0) str[i].c=0; if(strcmp(tmp,"good")==0) str[i].c=1; if(strcmp(tmp,"wonderful")==0) str[i].c=2; } sort(str,str+n,cmp); //for(int i=0;i<n;i++) //cout<<str[i].a<<" "<<str[i].b<<" "<<str[i].c<<endl; cout<<"Case "<<l++<<endl; cout<<str[0].b<<":"<<endl; cout<<" "<<str[0].a<<" "<<k[str[0].c]<<endl; for(int i=1;i<n;i++) { if(strcmp(str[i].b,str[i-1].b)==0) cout<<" "<<str[i].a<<" "<<k[str[i].c]<<endl; else { cout<<str[i].b<<":"<<endl; cout<<" "<<str[i].a<<" "<<k[str[i].c]<<endl; } } }return 0;}
加油!
0 0
- Hdu 3293 - sort
- HDU 3293 sort
- hdu 3293 sort
- HDU 3293:sort
- HDU 3293 sort [Ad Hoc]
- hdu sort
- HDU sort
- HDU sort
- hdu 1425 sort
- HDU 1425 ( sort )
- HDU 1425 sort
- HDU 1425 sort
- hdu 1089 Robotic Sort
- hdu 1209 #sort
- hdu 1425.sort
- HDU 2523 SORT AGAIN
- hdu 1425 sort
- hdu 2689 Sort it
- 跳转微信
- 用swoole扩展编写WebSocket聊天室
- Binary Tree Level Order Traversal
- iOS 富文本
- DAY7:leetcode #16 3Sum Closest
- HDU 3293:sort
- Day10 远程服务与本地服务
- iOS 为自定义返回按钮的页面添加右滑返回
- UBUNTU 创建samba服务
- 在myeclipse中出现Parse error in application web.xml file 问题
- Jboss jar包冲突及jar加载顺序
- 路在何方
- 数据库分类
- UVA 10305