题意:德才均大于及格线low的才进行排序,排序的人按种姓分为 :) sages-nobleman-fool man-trash
对于人的类型的排序只需要在结构体中加入一个int type即可,通过这个数字来进行类型排序
AC代码:
//1062 Talent and Virtue (25分) https://pintia.cn/problem-sets/994805342720868352/problems/994805410555346944
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char str[5][10] = { "","trash","fool man","nobleman","sages" };
struct student {
char id[10];
int talent;
int virtue;
int total;
int type;//四种类型,从4到1
}stu[100010];
void classify(student *s,int low,int high)
{
int x = s->talent, y = s->virtue;
if (x >= high && y >= high)
s->type = 4;
else if (y >= high && x < high) s->type = 3;
else if (x < high && y < high && y >= x) s->type = 2;
else s->type = 1;
}
bool cmp(student p1, student p2)//分数比较
{
if (p1.type != p2.type) return p1.type > p2.type;
else if (p1.total != p2.total) return p1.total > p2.total;
else if (p1.virtue != p2.virtue) return p1.virtue > p2.virtue;
else return strcmp(p1.id, p2.id) < 0;
}
int main()
{
int N, count = 0;
scanf("%d", &N);
int low, high;
scanf("%d%d", &low, &high);
for (int i = 0; i < N; i++) {
int t, v;
char s[10] = { 0 };
scanf("%s %d %d",s,&v,&t);
if (t >= low && v >= low) {//过滤掉德或才不及格的人
strcpy(stu[count].id, s);
stu[count].talent = t;
stu[count].virtue = v;
stu[count].total = t + v;
classify(stu+count, low, high);
count++;
}
}
sort(stu, stu + N, cmp);
printf("%d\n", count);
for (int i = 0; i < count; i++) {
printf("%s %d %d\n", stu[i].id, stu[i].virtue, stu[i].talent);
}
return 0;
}