二手的家具哪个网站做的好,下载网站的表格要钱如何做,做本地网站能赚钱么,合肥 网站建设ZZULIOJ 1185: 添加记录#xff08;结构体专题#xff09;#xff0c;Java
题目描述
有一学生成绩表#xff0c;包括学号、姓名、3门课程成绩。已知该成绩表按学号升序排序。请编程实现#xff0c;添加一个新的学生信息#xff0c;且使成绩表仍按学号有序#xff1b;若…ZZULIOJ 1185: 添加记录结构体专题Java
题目描述
有一学生成绩表包括学号、姓名、3门课程成绩。已知该成绩表按学号升序排序。请编程实现添加一个新的学生信息且使成绩表仍按学号有序若待添加的学号与已有学号重复则输出错误信息拒绝添加。
输入
首先输入一个整数 n ( 1 n 100 ) n(1n100) n(1n100) 表示学生人数 然后输入n行每行包含一个学生的信息学号12位、姓名不含空格且不超过20位以及3个整数表示3门课成绩数据之间用空格隔开。 最后一行输入一个待添加的学生信息包括学号、姓名和3门课成绩
输出
若待添加的学号与已有学号重复则输出只有一行 error! 否则输出n1行即添加后的成绩单信息。
样例输入 Copy
3
541207010188 Zhangling 78 95 55
541207010189 Wangli 87 99 88
541207010191 Fangfang 68 76 75
541207010190 Lilei 68 79 82样例输出 Copy
541207010188 Zhangling 78 95 55
541207010189 Wangli 87 99 88
541207010190 Lilei 68 79 82
541207010191 Fangfang 68 76 75import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;class Student implements ComparableStudent {String id, name;int a, b, c;public Student(String id, String name, int a, int b, int c) {this.id id;this.name name;this.a a;this.b b;this.c c;}public int compareTo(Student other) {return this.id.compareTo(other.id);}
}public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);int n sc.nextInt();ArrayListStudent students new ArrayList();for (int i 0; i n; i) {String id sc.next();String name sc.next();int a sc.nextInt();int b sc.nextInt();int c sc.nextInt();students.add(new Student(id, name, a, b, c));}String newId sc.next();String newName sc.next();int newA sc.nextInt();int newB sc.nextInt();int newC sc.nextInt();boolean studentExists students.stream().anyMatch(student - student.id.equals(newId));if (studentExists) {System.out.println(error!);} else {students.add(new Student(newId, newName, newA, newB, newC));Collections.sort(students);for (Student student : students) {System.out.println(student.id student.name student.a student.b student.c);}}}
}