您的位置:首页 > 其它

hdu3293(字符串排序)

2016-06-25 13:56 281 查看
[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

排序策略:

1:持有者名字

2:武器级别

3:武器名字

输出憋忘了case哟……

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
struct data
{
char mz[25],jb[25],wq[25];
} a[510];

bool cmp(data a,data b)
{
if(strcmp(a.mz,b.mz))
return strcmp(a.mz,b.mz)<0;
if(strcmp(a.jb,b.jb))
return strcmp(a.jb,b.jb)<0;
return strcmp(a.wq,b.wq)<0;
}

void change(int i)
{
if(a[i].jb[0]=='s')
a[i].jb[0]='c';
else if(a[i].jb[0]=='g')
a[i].jb[0]='b';
else
a[i].jb[0]='a';
}
void beback(int i)
{
if(a[i].jb[0]=='c')
a[i].jb[0]='s';
else if(a[i].jb[0]=='b')
a[i].jb[0]='g';
else
a[i].jb[0]='w';
}
int main()
{
int n,o=1;
while(~scanf("%d",&n))
{
for(int i=1; i<=n; i++)
{
scanf("%s%s%s",a[i].wq,a[i].mz,a[i].jb);
change(i);
}
printf("Case %d\n",o++);
sort(a+1,a+n+1,cmp);
strcpy(a[0].mz,a[1].mz);
a[0].mz[0]+=5;
for(int i=1; i<=n; i++)
{
if(strcmp(a[i].mz,a[i-1].mz))
printf("%s:\n",a[i].mz);
beback(i);
printf(" %s %s\n",a[i].wq,a[i].jb);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  大二 acm