58,454
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
class Student implements Comparable {
private int no;
private String name;
private int score;
public Student(int no, String name, int score) {
this.no = no;
this.name = name;
this.score = score;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return no == student.no;
}
@Override
public int hashCode() {
return Objects.hash(no);
}
@Override
public String toString() {
return "no:" + this.no + " name:" + this.name + " score:" + this.score;
}
@Override
public int compareTo(Object o) {
return this.no - ((Student)o).getNo();
}
}
public class testmain12{
public static void main(String[] args) {
List <Student> list = new LinkedList<Student>();
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
for (int i = 0; i < num;++i) {
list.add(new Student (sc.nextInt(),sc.next(),sc.nextInt()));
}
num = sc.nextInt();
for (int i = 0; i < num; ++i) {
String s = sc.next();
switch (s) {
case "add":
list.add(new Student (sc.nextInt(),sc.next(),sc.nextInt()));
case "delete":
int n = sc.nextInt();
int len = list.size();
for (int j = 0; j < len;++j) {
if (list.get(j).getNo() == n)list.remove(j);
break;
}
case "set" :
int nn = sc.nextInt();
int score = sc.nextInt();
int lenl = list.size();
for (int j = 0; j < lenl;++j) {
if (list.get(j).getNo() == nn) {
list.get(j).setScore(score);
break;
}
}
}
}
Object[] objects = list.toArray();
Arrays.sort(objects);
for(int j = 0; j < objects.length; j++) {
System.out.println(objects[j]);
}
/*int l = list.size();
for (int k = 0; k < l; ++k)System.out.println(list.get(i));*/
sc.close();
}
}