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.

Each string will not exceed 20 characters.
Sure that same origin will not exist the same weapon.
5 knife qizhou so-so gun qizhou wonderful knife zhengzhou good stick zhengzhou good rope shengzhou so-so
Case 1 qizhou: gun wonderful knife so-so shengzhou: rope so-so zhengzhou: knife good stick good
#include<bits/stdc++.h>
using namespace std;
struct pp
{
string ori,na,le;
int l;
};
pp p[510];
bool cmp(const pp&a,const pp&b)
{
if(a.ori!=b.ori)
return a.ori<b.ori;
else if(a.l!=b.l)
return a.l<b.l;
else
return a.na<b.na;
}
set<string>origin;
int main()
{
int n,t=1;
while(cin>>n)
{
string a,b,c;
for(int i=0;i<n;i++)
{
cin>>p[i].na>>p[i].ori>>p[i].le;
origin.insert(p[i].ori);
if(p[i].le[0]=='w')
p[i].l=1;
else if(p[i].le[0]=='g')
p[i].l=2;
else
p[i].l=3;
}
int l=0;
sort(p,p+n,cmp);
cout<<"Case "<<t<<endl;
for(set<string>::iterator it=origin.begin();it!=origin.end();it++)
{
cout<<*it<<":\n";
for(;l<n&&*it==p[l].ori;l++)
cout<<" "<<p[l].na<<" "<<p[l].le<<endl;
}
t++;
origin.clear();
}
return 0;
}
2600



被折叠的 条评论
为什么被折叠?



