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.
![](http://acm.hdu.edu.cn/data/images/C251-1006-1.jpg)
[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;
}
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.
![](http://acm.hdu.edu.cn/data/images/C251-1006-1.jpg)
[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;
}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe