怎么做网站扩展,网站建设公式,网站安全建设经费保障,html 社区网站 模板题目描述#xff1a; 宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”#xff1a;“是故才德全尽谓之圣人#xff0c;才德兼亡谓之愚人#xff0c;德胜才谓之君子#xff0c;才胜德谓之小人。凡取人之术#xff0c;苟不得圣人#xff0c;君子而与之#xff0c…题目描述 宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”“是故才德全尽谓之圣人才德兼亡谓之愚人德胜才谓之君子才胜德谓之小人。凡取人之术苟不得圣人君子而与之与其得小人不若得愚人。” 现给出一批考生的德才分数请根据司马光的理论给出录取排名。 输入描述: 输入第1行给出3个正整数分别为N105即考生总数L60为录取最低分数线即德分和才分均不低于L的考生才有资格被考虑录取H100为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”此类考生按德才总分从高到低排序才分不到但德分到线的一类考生属于“德胜才”也按总分排序但排在第一类考生之后德才分均低于H但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者按总分排序但排在第二类考生之后其他达到最低线L的考生也按总分排序但排在第三类考生之后。 随后N行每行给出一位考生的信息包括准考证号、德分、才分其中准考证号为8位整数德才分为区间[0,100]内的整数。数字间以空格分隔。 输出描述: 输出第1行首先给出达到最低分数线的考生人数M随后M行每行按照输入格式输出一位考生的信息考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时按其德分降序排列若德分也并列则按准考证号的升序输出。 输入例子: 14 60 80 10000001 64 90 10000002 90 60 10000011 85 80 10000003 85 80 10000004 80 85 10000005 82 77 10000006 83 76 10000007 90 78 10000008 75 79 10000009 59 90 10000010 88 45 10000012 80 100 10000013 90 99 10000014 66 60
输出例子: 12 10000013 90 99 10000012 80 100 10000003 85 80 10000011 85 80 10000004 80 85 10000007 90 78 10000006 83 76 10000005 82 77 10000002 90 60 10000014 66 60 10000008 75 79 10000001 64 90
Java代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scanner new Scanner(System.in);int n scanner.nextInt();int l scanner.nextInt();int h scanner.nextInt();ArrayListStudent students new ArrayList();int i 0;while (i n){Integer no scanner.nextInt();int de scanner.nextInt();int cai scanner.nextInt();Student student new Student(no, de, cai, l, h);if (student.s ! 0) students.add(student);}Collections.sort(students, new ComparatorStudent() {Overridepublic int compare(Student o1, Student o2) {if (o1.s ! o2.s) return o1.s - o2.s;else if (o1.deo1.cai ! o2.de o2.cai) return (o2.de o2.cai)-(o1.deo1.cai);else if (o1.de ! o2.de) return o2.de - o1.de;else return o1.no - o2.no;}});System.out.println(students.size());students.forEach(System.out::println);}static class Student {Integer no 0;int de 0;int cai 0;int l 0;int h 0;int s 0;public Student(Integer no, int de, int cai, int l, int h) {this.no no;this.de de;this.cai cai;this.l l;this.h h;if (de h cai h){s 1;}else if (de h cai l){s 2;}else if (de l cai l de cai){s 3;}else if (de l cai l){s 4;}}Overridepublic String toString() {return no de cai;}}
}