1015 德才论 (25 分)

题目链接

  1. 根据输入的数据对学生的成绩进行排序然后输出即可,就是规则有些绕口。
  2. L为录取最低分数线,H为优先录取线
  3. (德>=H) 并且 (才>= H) 为“才德全尽”,第一梯队,按总分排序
  4. (德>=H)并且 (H>才>=L)为“德胜才”,第二梯队,按总分排序
  5. (H>德>=L) 并且 (H>才>=L) 并且 (德>=才)为“才德兼亡”但尚有“德胜才”,第三梯队,按总分排序
  6. 其他 (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()
复制代码

转载于:https://juejin.im/post/5ce7d7b7f265da1b6c5f509c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值