HDU 3293 sort
2013-06-10 12:22
183 查看
sort
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 591 Accepted Submission(s): 271
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
Please output your list after sorting (format according to sample, pay attention to the spaces,ten spaces need ^ ^).
[align=left]Sample Input[/align]
5
knife qizhou so-so
gun qizhou wonderful
knife zhengzhou good
stick zhengzhou good
rope shengzhou so-so
[align=left]Sample Output[/align]
Case 1
qizhou:
gun wonderful
knife so-so
shengzhou:
rope so-so
zhengzhou:
knife good
stick good
[align=left]Author[/align]
wangjing1111
[align=left]Source[/align]
2010 “HDU-Sailormoon” Programming Contest
[align=left]Recommend[/align]
lcy
排序水题:
优先级如下: 1.中间的origin 按字典序排序
2.最后面的level 按wonderful good so-so排序
3.最前面的weapon 按字典序排序
#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef struct Node { string fri; string sec; string thr; }; int cmp (Node a, Node b) { if(a.sec == b.sec) { if(a.thr == b.thr) return a.fri < b.fri; else return a.thr < b.thr; } else return a.sec < b.sec; } int main () { int n, i, j; int t = 1; while(scanf("%d", &n)!=EOF) { printf("Case %d\n",t++); Node str[505]; for(i = 0; i < n; i++) { string temp ; cin >> str[i].fri; cin >> str[i].sec; cin >> temp; //此地处理一下 以便后面排序 if(temp == "wonderful") str[i].thr = "a"; else if(temp == "good") str[i].thr = "b"; else str[i].thr = "c"; } sort(str, str+n, cmp); string temp = " "; for(i = 0; i < n; i++) { if(temp != str[i].sec) { cout << str[i].sec <<":"<<endl; temp = str[i].sec; } cout <<" " <<str[i].fri << " "; if(str[i].thr == "a") str[i].thr = "wonderful"; else if (str[i].thr == "b") str[i].thr = "good"; else str[i].thr = "so-so"; cout << str[i].thr << endl; } } return 0; }
相关文章推荐
- HDU 3293:sort
- HDU 3293 sort(结构体排序)
- HDU-3293-sort
- hdu 3293 sort
- Hdu 3293 - sort
- HDU 3293 sort
- HDU 3293 sort
- sort(HDU-3293)
- HDU 3293 sort
- HDU--杭电--3293--sort--结构体排序
- hdu 2689 Sort it
- HDU 3466 - Proud Merchants (01背包+sort)
- hdu 5884 Sort 二分+K哈夫曼树(解决不单调问题) 队列优化
- HDU 4857 topological_sort
- hdu 2056 排序sort
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- HDU 1890 Robotic Sort 伸展树的区间反转与延迟标记
- hdu 1234_sort的陷阱
- hdu 1009 肥胖鼠 贪心(一) sort 排序函数
- HDU1890 Robotic Sort(slpay,区间旋转)