题目链接:https://www.patest.cn/contests/pat-a-practise/1062
本题比较简单,就是一个排序的问题,用STL的sort方法
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
struct Person{
int ID;
int Talent;
int Virtue;
Person(){}
Person(int id , int talent , int virtue): ID(id) , Talent(talent) , Virtue(virtue){}
};
bool cmp(const Person &a, const Person &b){
if(a.Talent+a.Virtue != b.Talent+b.Virtue)return a.Talent+a.Virtue > b.Talent+b.Virtue;
else if(a.Virtue != b.Virtue)return a.Virtue > b.Virtue;
else return a.ID < b.ID;
}
int main(){
vector<Person> sages , noblemen , foolmen, others;
int n=0 , L=0 , H=0;
cin>>n>>L>>H;
for(int i=0; i<n; i++){
int id , talent , virtue;
cin>>id>>virtue >>talent;
if(talent>=H && virtue>=H)sages.push_back(Person( id , talent , virtue ));
else if(talent>=L && virtue>=H)noblemen.push_back(Person( id , talent , virtue ));
else if(talent>=L && virtue>=L && virtue>=talent )foolmen.push_back(Person( id , talent , virtue ));
else if(talent>=L && virtue>=L)others.push_back(Person( id , talent , virtue ));
}
sort(sages.begin() , sages.end() , cmp);
sort(noblemen.begin() , noblemen.end() , cmp);
sort(foolmen.begin() , foolmen.end() , cmp);
sort(others.begin() , others.end() , cmp);
cout<<sages.size()+noblemen.size()+foolmen.size()+others.size()<<endl;
for(int i=0;i<sages.size();i++)printf("%d %d %d\n",sages[i].ID , sages[i].Virtue , sages[i].Talent);
for(int i=0;i<noblemen.size();i++)printf("%d %d %d\n",noblemen[i].ID , noblemen[i].Virtue , noblemen[i].Talent);
for(int i=0;i<foolmen.size();i++)printf("%d %d %d\n",foolmen[i].ID , foolmen[i].Virtue , foolmen[i].Talent);
for(int i=0;i<others.size();i++)printf("%d %d %d\n",others[i].ID , others[i].Virtue , others[i].Talent);
return 0;
}