试题 算法提高 学生成绩统计
Lan
2020-04-01 12:52
203 人阅读
0 条评论
资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
编写一个程序,建立了一条单向链表,每个结点包含姓名、学号、英语成绩、数学成绩和C++成绩,并通过链表操作平均最高的学生和平均分最低的学生并且输出。
输入格式
输入n+1行,第一行输入一个正整数n,表示学生数量;接下来的n行每行输入5个数据,分别表示姓名、学号、英语成绩、数学成绩和C++成绩。注意成绩有可能会有小数。
输出格式
输出两行,第一行输出平均成绩最高的学生姓名。第二行输出平均成绩最低的学生姓名。
样例输入
2
yx1 1 45 67 87
yx2 2 88 90 99
yx1 1 45 67 87
yx2 2 88 90 99
样例输出
yx2
yx1
yx1
import java.util.*;
public class 学生成绩统计 {
/**
* @param args
*/
public static class student{
public String name;
public double grade;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
student[] stu = new student[n];
student max = new student();
student min = new student();
min.grade=100;
for (int i = 0; i < stu.length; i++) {
stu[i] = new student();
stu[i].name = sc.next();
double id = sc.nextDouble();
double eng = sc.nextDouble();
double math = sc.nextDouble();
double c = sc.nextDouble();
stu[i].grade = (eng+math+c)/3;
if (stu[i].grade>max.grade) {
max = stu[i];
}
if (stu[i].grade<min.grade) {
min = stu[i];
}
}
System.out.println(max.name);
System.out.println(min.name);
}
}
赞赏
![打赏二维码](https://i-blog.csdnimg.cn/blog_migrate/3a584bda34e1671c4a5d6ebe99b9718e.png)