暴力代码,水了\(22pts\)。
const int N=1e5+10;
struct Node
{
string name;
int age;
int worth;
bool operator<(const Node &W) const
{
if(worth != W.worth) return worth > W.worth;
if(age != W.age) return age < W.age;
return name < W.name;
}
}a[N];
int n,m;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i].name>>a[i].age>>a[i].worth;
int kase=1;
while(m--)
{
int k,l,r;
cin>>k>>l>>r;
vector<Node> v;
for(int i=0;i<n;i++)
if(a[i].age >= l && a[i].age <= r)
v.pb(a[i]);
cout<<"Case #"<<kase++<<‘:‘<<endl;
if(v.size() == 0) cout<<"None"<<endl;
else
{
sort(v.begin(),v.end());
for(int i=0;i<k && i<v.size();i++)
cout<<v[i].name<<‘ ‘<<v[i].age<<‘ ‘<<v[i].worth<<endl;
}
}
//system("pause");
return 0;
}
1055 The World's Richest (25 分)
原文:https://www.cnblogs.com/fxh0707/p/14403398.html