1. Scanner sc = new Scanner(System.in);
  2. int n = sc.nextInt();
  3. Student2[] stu = new Student2[n];
  4. for (int i = 0; i < stu.length; i++) {
  5. stu[i] = new Student2();
  6. }
  7. for (int i = 0; i < stu.length; i++) {// 输入学生数据
  8. stu[i].setSno(sc.next());
  9. stu[i].setName(sc.next());
  10. stu[i].setScoreA(sc.nextInt());
  11. stu[i].setScoreB(sc.nextInt());
  12. stu[i].setScoreC(sc.nextInt());
  13. }
  14. int[] sum = new int[n];// 成绩数组
  15. int A = 0;// 分别输入三科成绩
  16. int B = 0;
  17. int C = 0;
  18. int max = 0;
  19. int index = 0;// 总分最高的学生的下标
  20. for (int i = 0; i < stu.length; i++) {
  21. // 存储每个学生的总成绩和各科成绩
  22. sum[i] = stu[i].getScoreA()+stu[i].getScoreB()+stu[i].getScoreC();
  23. max = sum[0];
  24. if (max < sum[i]){// 找出总分最高的学生的下标index
  25. max = sum[i];
  26. index = i;
  27. }
  28. A += stu[i].getScoreA();
  29. B += stu[i].getScoreB();
  30. C += stu[i].getScoreC();
  31. }
  32. System.out.println(A/n+" "+B/n+" "+C/n);// 各科的平均成绩
  33. System.out.println(stu[index].getSno()+" "+stu[index].getName()+" "+stu[index].getScoreA()+" "+stu[index].getScoreB()+" "+stu[index].getScoreC());
  34. }
  35. }
  36. class Student2{
  37. private String sno;
  38. private String name;
  39. private int[] Score = new int[3];
  40. public String getSno() {
  41. return sno;
  42. }
  43. public void setSno(String sno) {
  44. this.sno = sno;
  45. }
  46. public String getName() {
  47. return name;
  48. }
  49. public void setName(String name) {
  50. this.name = name;
  51. }
  52. public int getScoreA() {
  53. return Score[0];
  54. }
  55. public int getScoreB() {
  56. return Score[1];
  57. }
  58. public int getScoreC() {
  59. return Score[2];
  60. }
  61. public void setScoreA(int score) {
  62. Score[0] = score;
  63. }
  64. public void setScoreB(int score) {
  65. Score[1] = score;
  66. }
  67. public void setScoreC(int score) {
  68. Score[2] = score;
点赞(0)
 

9 分

1 人评分

 

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论