某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:
院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;
五四奖学金,每人4000元,期末平均成绩高于85分(>85),并且班级评议成绩高于80分(>80)的学生均可获得;
成绩优秀奖,每人2000元,期末平均成绩高于90分(>90)的学生均可获得;
西部奖学金,每人1000元,期末平均成绩高于85分(>85)的西部省份学生均可获得;
班级贡献奖,每人850元,班级评议成绩高于80分(>80)的学生干部均可获得;
只要符合条件就可以得奖,每项奖学金的获奖人数没有限制,每名学生也可以同时获得多项奖学金。例如姚林的期末平均成绩是87分,班级评议成绩82分,同时他还是一位学生干部,那么他可以同时获得五四奖学金和班级贡献奖,奖金总数是4850元。
基本要求
现在给出若干学生的相关数据,请计算哪些同学获得的奖金总数最高(假设总有同学能满足获得奖学金的条件)。
输入数据格式格式:
输入的第一行是一个整数N(1 <= N <= 100),表示学生的总数。接下来的N行每行是一位学生的数据,从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是否是西部省份学生,以及发表的论文数。姓名是由大小写英文字母组成的长度不超过20的字符串(不含空格);期末平均成绩和班级评议成绩都是0到100之间的整数(包括0和100);是否是学生干部和是否是西部省份学生分别用一个字符表示,Y表示是,N表示不是;发表的论文数是0到10的整数(包括0和10)。每两个相邻数据项之间用一个空格分隔。
输出数据格式:
输出包括三行,第一行是获得最多奖金的学生的姓名,第二行是这名学生获得的奖金总数。如果有两位或两位以上的学生获得的奖金最多,输出他们之中在输入文件中出现最早的学生的姓名。第三行是这N个学生获得的奖学金的总数。
输入
4
YaoLin 87 82 Y N 0
ChenRuiyi 88 78 N Y 1
LiXin 92 88 N N 0
ZhangQin 83 87 Y N 1
输出
ChenRuiyi
9000
28700
main函数
package hello;
import java.util.*;
public class Scholarship {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("请输入学生个数和" +
"学生信息:(学生姓名 平均成绩 评议成绩 是否为干部 是否为西部省份学生 写过几篇论文)");
List<Student> studentList=new ArrayList<Student>();
String inputCount=scanner.nextLine();
int inputCount2=Integer.parseInt(inputCount);
for(int i=0;i<inputCount2;i++)
{
String input=scanner.nextLine();
String[] info=input.split(" ");
int avgScore=Integer.parseInt(info[1]);
int dayScore=Integer.parseInt(info[2]);
int paperCount=Integer.parseInt(info[5]);
boolean isCadre=false;
boolean isWest=false;
if(info[3].equals("Y"))
{
isCadre=true;
}
else {
isCadre=false;
}
if(info[4].equals("Y"))
{
isWest=true;
}
else {
isWest=false;
}
Student student=new Student(info[0],avgScore,dayScore,isCadre,isWest,paperCount);
studentList.add(student);
}
for(Student student:studentList)
{
int sum=0;
if(student.getAvgScore()>80&&student.getPaperCount()>=1)
{
sum+=8000;
}
if(student.getAvgScore()>85&&student.getDayScore()>80)
{
sum+=4000;
}
if(student.getAvgScore()>90)
{
sum+=2000;
}
if(student.getAvgScore()>85&&student.isWest()==true)
{
sum+=1000;
}
if(student.getAvgScore()>80&&student.isCadre()==true)
{
sum+=850;
}
student.setScholarship(sum);
}
List<Student> oldStudentList=new ArrayList<Student>();
for(Student student:studentList)
{
oldStudentList.add(student);
}
Collections.sort(studentList);
Set<Student> maxScholarshipStudent=new HashSet<Student>();
for(int i=0;i<studentList.size();i++)
{
if(i==studentList.size()-1)
{
break;
}
else if(studentList.get(i).getScholarship()==studentList.get(i+1).getScholarship())
{
maxScholarshipStudent.add(studentList.get(i));
maxScholarshipStudent.add(studentList.get(i+1));
}
}
if(maxScholarshipStudent.size()==0)
{
maxScholarshipStudent.add(studentList.get(0));
}
int sum=0;
for(Student student:maxScholarshipStudent)
{
sum+=student.getScholarship();
}
Student outputStudent=new Student();
for(Student student:oldStudentList)
{
if(maxScholarshipStudent.contains(student))
{
outputStudent=student;
break;
}
}
System.out.println("奖学金最多的人是"+outputStudent.getName());
System.out.println("奖学金是"+outputStudent.getScholarship());
if(maxScholarshipStudent.size()>1)
{
System.out.println("总奖金为"+sum+"元");
}
}
}
Student类
package hello;
public class Student implements Comparable{
private String name;
private int avgScore;
private int dayScore;
private boolean isCadre;
private boolean isWest;
private int paperCount;
private int scholarship;
public Student(){
}
public Student(String name, int avgScore, int dayScore, boolean isCadre, boolean isWest, int paperCount) {
this.name = name;
this.avgScore = avgScore;
this.dayScore = dayScore;
this.isCadre = isCadre;
this.isWest = isWest;
this.paperCount = paperCount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAvgScore() {
return avgScore;
}
public void setAvgScore(int avgScore) {
this.avgScore = avgScore;
}
public int getDayScore() {
return dayScore;
}
public void setDayScore(int dayScore) {
this.dayScore = dayScore;
}
public boolean isCadre() {
return isCadre;
}
public void setCadre(boolean cadre) {
isCadre = cadre;
}
public boolean isWest() {
return isWest;
}
public void setWest(boolean west) {
isWest = west;
}
public int getPaperCount() {
return paperCount;
}
public void setPaperCount(int paperCount) {
this.paperCount = paperCount;
}
public int getScholarship() {
return scholarship;
}
public void setScholarship(int scholarship) {
this.scholarship = scholarship;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", avgScore=" + avgScore +
", dayScore=" + dayScore +
", isCadre=" + isCadre +
", isWest=" + isWest +
", paperCount=" + paperCount +
", scholarship=" + scholarship +
'}';
}
@Override
public int compareTo(Object o) {
Student student=(Student)o;
return student.getScholarship()-this.getScholarship();
}
}