您的位置:首页 > 其它

PAT乙级(Basic Level)真题 >德才论

2017-04-01 21:11 337 查看
题目描述

宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之

小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”

现给出一批考生的德才分数,请根据司马光的理论给出录取排名。

输入描述:

输入第1行给出3个正整数,分别为:N(<=105),即考生总数;L(>=60),为录取最低分数线,即德分和才分均不低于L的考生才有资格

被考虑录取;H(<100),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到

但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于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

import java.util.*;

class Result{
private String num;
private int moral;
private int talent;
public Result(String num,int moral,int talent){
this.num = num;
this.moral=moral;
this.talent = talent;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public int getMoral() {
return moral;
}
public void setMoral(int moral) {
this.moral = moral;
}
public int getTalent() {
return talent;
}
public void setTalent(int talent) {
this.talent = talent;
}
public String toString() {
return num + " " + moral + " " + talent;
}
}

class cmp implements Comparator{
public int compare(Object o1,Object o2){
Result r1 = (Result)o1;
Result r2 = (Result)o2;
int m1 = r1.getMoral(),m2 = r2.getMoral();
int t1 = r1.getTalent(),t2 = r2.getTalent();
if(m1+t1 != m2+t2){
return (m2+t2)-(m1+t1);
}
else if(m1 != m2){
return m2-m1;
}else{
return r1.getNum().compareTo(r2.getNum());
}
}
}

public class PAT1005 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
ArrayList<Result> RA1 = new ArrayList<Result>(); //第一等
ArrayList<Result> RA2 = new ArrayList<Result>(); //第二等
ArrayList<Result> RA3 = new ArrayList<Result>(); //第三等
ArrayList<Result> RA4 = new ArrayList<Result>(); //第四等
int N = in.nextInt();
int L = in.nextInt();
int H = in.nextInt();
String num;
int m,t;
for(int i = 0;i<N;i++){
num = in.next();
m = in.nextInt();
t = in.nextInt();
Result S = new Result(num,m,t);
if(m>=L && t>=L){
if(m>=H && t>=H){
RA1.add(S);
}
else if(m>=H && t<H){
RA2.add(S);
}
else if(m<H && t<H && m>=t){
RA3.add(S);
}
else{
RA4.add(S);
}
}
}

int count = RA1.size()+RA2.size()+RA3.size()+RA4.size();
System.out.println(count);
Collections.sort(RA1, new cmp());
Collections.sort(RA2, new cmp());
Collections.sort(RA3, new cmp());
Collections.sort(RA4, new cmp());
for (Result s : RA1) {
System.out.println(s.toString());
}
for (Result s : RA2) {
System.out.println(s.toString());
}
for (Result s : RA3) {
System.out.println(s.toString());
}
for (Result s : RA4) {
System.out.println(s.toString());
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: