题目:https://www.patest.cn/contests/pat-b-practise/1015
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; struct person{ int id,de,cai; int score; }; bool cmp(person a,person b){ if(a.score!=b.score) return a.score>b.score; else if(a.de!=b.de) return a.de>b.de; else return a.id<b.id; } int main(){ int n,l,h; scanf("%d%d%d",&n,&l,&h); person temp; int count=0; vector<person>v1,v2,v3,v4; for(int i=0;i<n;i++){ scanf("%d%d%d",&temp.id,&temp.de,&temp.cai); temp.score=temp.de+temp.cai; if(temp.de>=l&&temp.cai>=l){ count++; if(temp.de>=h&&temp.cai>=h){ v1.push_back(temp); } else if(temp.de>=h&&temp.cai<h){ v2.push_back(temp); }else if (temp.de<h&&temp.cai<h&&temp.de>=temp.cai){ v3.push_back(temp); }else v4.push_back(temp); } } printf("%d\n",count); sort(v1.begin(),v1.end(),cmp); sort(v2.begin(),v2.end(),cmp); sort(v3.begin(),v3.end(),cmp); sort(v4.begin(),v4.end(),cmp); vector<person>::iterator it; for (it = v1.begin(); it != v1.end(); ++it) printf("%d %d %d\n", it->id, it->de, it->cai); for (it = v2.begin(); it!= v2.end(); ++it) printf("%d %d %d\n", it->id, it->de, it->cai); for (it = v3.begin(); it != v3.end(); ++it) printf("%d %d %d\n", it->id, it->de, it->cai); for (it = v4.begin(); it != v4.end(); ++it) printf("%d %d %d\n", it->id, it->de, it->cai);
return 0; }