对所有数据进行排序,再将其保存到题目各个要求的位置,最后将其输出
#include<iostream>#include<vector>#include<algorithm>#include<string>#PRagma warning(disable :4996)using namespace std;struct node {//people并创建排列的顺序 string id; int V, T; bool Operator<(const node that) const { return (this->V + this->T>that.V + that.T || (this->V + this->T == that.V + that.T && this->V > that.V) || (this->V + this->T == that.V + that.T && this->V == that.V && this->id < that.id)); }};int main(){ vector<node> a, b, c, d, all;//all保存所有的输入,a,b,c,d分别保存圣人、君子、愚人、小人的人node int N, L, H; cin >> N >> L >> H; all.resize(N); for (int i = 0;i < N;i++) { char t[100]; scanf("%s %d %d", t, &all[i].V, &all[i].T); all[i].id = t; } sort(all.begin(), all.end());//对所有数据先排好序,在一个个输出到abcd四个容器中 int count = 0; for (auto x : all) { if (x.T >= L &&x.V >= L) { count++; if (x.T >= H &&x.V >= H) a.push_back(x); else if (x.V >= H && x.T < H) b.push_back(x); else if (x.V < H &&x.T < H&&x.V >= x.T) c.push_back(x); else d.push_back(x); } } cout << count << endl;//输出结果 for (auto x : a) printf("%s %d %d/n", x.id.c_str(), x.V, x.T); for (auto x : b) printf("%s %d %d/n", x.id.c_str(), x.V, x.T); for (auto x : c) printf("%s %d %d/n", x.id.c_str(), x.V, x.T); for (auto x : d) printf("%s %d %d/n", x.id.c_str(), x.V, x.T);}新闻热点
疑难解答