#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100000;
struct people {
char id[15];
int virtue, talent;
};
bool comp(people p1, people p2);
void copy(people &p1, people &p2) {
strcpy(p1.id, p2.id);
p1.virtue = p2.virtue;
p1.talent = p2.talent;
return;
}
void print(people p[], int cnt);
int main(void) {
int sage_cnt, noble_cnt, fool_cnt, small_cnt, i, n, l, h;
people *noble = new people[N], *sage = new people[N], *fool = new people[N], *small = new people[N], tmp;
scanf("%d %d %d", &n, &l, &h);
sage_cnt = noble_cnt = fool_cnt = small_cnt = 0;
for (i = 0; i < n; i++) {
scanf("%s %d %d", tmp.id, &tmp.virtue, &tmp.talent);
if (tmp.virtue >= h && tmp.talent >= h) {
copy(sage[sage_cnt], tmp);
sage_cnt++;
}
else if (tmp.virtue >= h && tmp.talent >= l) {
copy(noble[noble_cnt], tmp);
noble_cnt++;
}
else if (tmp.virtue >= l && tmp.talent >= l && tmp.virtue >= tmp.talent) {
copy(fool[fool_cnt], tmp);
fool_cnt++;
}
else if (tmp.virtue >= l && tmp.talent >= l) {
copy(small[small_cnt], tmp);
small_cnt++;
}
}
sort(sage, sage + sage_cnt, comp);
sort(noble, noble + noble_cnt, comp);
sort(fool, fool + fool_cnt, comp);
sort(small, small + small_cnt, comp);
printf("%d\n", sage_cnt + noble_cnt + fool_cnt + small_cnt);
print(sage, sage_cnt);
print(noble, noble_cnt);
print(fool, fool_cnt);
print(small, small_cnt);
delete[] sage;
delete[] noble;
delete[] fool;
delete[] small;
return 0;
}
bool comp(people p1, people p2) {
if (p1.virtue + p1.talent > p2.virtue + p2.talent) {
return true;
}
else if (p1.virtue + p1.talent < p2.virtue + p2.talent) {
return false;
}
else {
if (p1.virtue > p2.virtue) {
return true;
}
else if (p1.virtue < p2.virtue) {
return false;
}
else {
int result = strcmp(p1.id, p2.id);
if (result < 0) {
return true;
}
else {
return false;
}
}
}
}
void print(people p[], int cnt) {
int i;
for (i = 0; i < cnt; i++) {
printf("%s %d %d\n", p[i].id, p[i].virtue, p[i].talent);
}
return;
}
1062. Talent and Virtue (25)解题报告
最新推荐文章于 2019-01-19 14:59:22 发布