题目链接
- 根据输入的数据对学生的成绩进行排序然后输出即可,就是规则有些绕口。
- L为录取最低分数线,H为优先录取线
- (德>=H) 并且 (才>= H) 为“才德全尽”,第一梯队,按总分排序
- (德>=H)并且 (H>才>=L)为“德胜才”,第二梯队,按总分排序
- (H>德>=L) 并且 (H>才>=L) 并且 (德>=才)为“才德兼亡”但尚有“德胜才”,第三梯队,按总分排序
- 其他 (H>德>=L) 并且 (H>才>=L) 并且 (德<才)为第四梯队,按总分排序
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
class student {
public:
int level, id, de, cai, total;
};
bool cmp(student& a, student& b) {
if (a.level != b.level)
return a.level < b.level;
else if (a.total != b.total)
return a.total > b.total;
else if (a.de != b.de)
return a.de > b.de;
else
return a.id < b.id;
}
int main() {
int n, low, high;
scanf("%d %d %d", &n, &low, &high);
vector <student > res;
student temp;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &temp.id, &temp.de, &temp.cai);
if (temp.de >= low && temp.cai >= low) {
temp.total = temp.cai + temp.de;
if (temp.de >= high && temp.cai >= high)
temp.level = 1;
else if (temp.de >= high && temp.cai >= low)
temp.level = 2;
else if (temp.de >= low && temp.cai >= low && temp.de >= temp.cai)
temp.level = 3;
else
temp.level = 4;
res.push_back(temp);
}
}
printf("%d\n", res.size());
sort(res.begin(),res.end(), cmp);
for (int j = 0; j < res.size(); j++)
printf("%d %d %d\n", res[j].id,res[j].de, res[j].cai);
return 0;
}
复制代码
import functools
class student:
level = 0
id = 0
cai = 0
de = 0
total = 0
def cmp(a,b):
if(a.level != b.level):
return a.level - b.level
elif(a.total != b.total):
return b.total - a.total
elif(a.de != b.de):
return b.de - a.de
else:
return a.id - b.id
def main():
a = input().split()
L = int(a[1])
H = int(a[2])
res =[]
for i in range(int(a[0])):
s = list(map(int,input().split()))
tmp = student()
tmp.id = s[0]
tmp.de = s[1]
tmp.cai = s[2]
if(s[1]>=L and s[2]>=L):
if(s[1] >= H and s[2] >= H):
tmp.level = 1
elif(s[1] >= H and s[2] >= L):
tmp.level = 2
elif(s[1]>=L and s[2] >= L and s[1] >= s[2]):
tmp.level = 3
else:
tmp.level = 4
tmp.total = tmp.cai + tmp.de
res.append(tmp)
res.sort(key=functools.cmp_to_key(cmp))
print(len(res))
for i in res:
print('{} {} {}'.format(i.id,i.de,i.cai))
main()
复制代码