1. 程式人生 > >1062 Talent and Virtue (25 分)

1062 Talent and Virtue (25 分)

1062 Talent and Virtue (25 分)

傳送門

#include <bits/stdc++.h>
using namespace std;
int n, lower, higher;

struct people{
	string name;
	int virtue;
	int talent;
};
bool cmp(people a, people 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.name<b.name; } } int main() { //freopen("datain.txt","r",stdin); cin>>n>>lower>>higher; vector<people>a,b,c,d; struct people temp; int m=0; for (int i = 0; i < n; i++) { cin >>
temp.name >> temp.virtue >> temp.talent; if (temp.talent<lower || temp.virtue<lower) continue; m++; if (temp.talent >= higher && temp.virtue >= higher) { a.push_back(temp); //a[0]代表聖人 a[1]代表君子 a[2]代表愚人 a[3]小人 } else if (temp.talent<higher && temp.
virtue>=higher) { b.push_back(temp); } else if (temp.talent<higher && temp.virtue<higher && temp.virtue>=temp.talent) { c.push_back(temp); } else { d.push_back(temp); } } sort(a.begin(),a.end(),cmp); sort(b.begin(),b.end(),cmp); sort(c.begin(),c.end(),cmp); sort(d.begin(),d.end(),cmp); cout << m << endl; for (int i = 0; i < a.size(); i++) { cout << a[i].name << " " << a[i].virtue << " " << a[i].talent << endl; } for (int i = 0; i < b.size(); i++) { cout << b[i].name << " " << b[i].virtue << " " << b[i].talent << endl; } for (int i = 0; i < c.size(); i++) { cout << c[i].name << " " << c[i].virtue << " " << c[i].talent << endl; } for (int i = 0; i < d.size(); i++) { cout << d[i].name << " " << d[i].virtue << " " << d[i].talent << endl; } return 0; }