解题思路:
注意事项:
eclipse上运行无错,答案正确,但是在题目下运行显示运行错误所以本答案仅供参考
参考代码:
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
class Student{
int Num;
int Grade;
public int getNum() {
return Num;
}
public void setNum(int num) {
Num = num;
}
public int getGrade() {
return Grade;
}
public void setGrade(int grade) {
Grade = grade;
}
public Student(int num, int grade) {
super();
Num = num;
Grade = grade;
}
public String toString() {
return this.Num+" "+ this.Grade;
}
public int hashCode(){
return this.Num;
}
}
public class Main{
public static void Link(int N,int M){
Scanner sc = new Scanner(System.in);
LinkedList<Student> listA = new LinkedList<>();
for(int i=0;i<N;i++){
listA.add(new Student(sc.nextInt(),sc.nextInt()));
}
LinkedList<Student> listB = new LinkedList<>();
for(int i=0;i<M;i++){
listB.add(new Student(sc.nextInt(),sc.nextInt()));
}
listA.addAll(listB);
HashSet<Student> hs = new HashSet<>(listA);
Iterator it = hs.iterator();
while(it.hasNext()){
System.out.print(it.next()+"\n");
}
}
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
Link(N,M);
}
}
0.0分
1 人评分
简单的a+b (C语言代码)浏览:673 |
C语言训练-大、小写问题 (C语言代码)浏览:2306 |
九宫重排 (C++代码)浏览:2153 |
C语言程序设计教程(第三版)课后习题9.8 (Java代码)浏览:1582 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:984 |
大小写转换 (C语言代码)浏览:818 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:549 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:530 |
WU-拆分位数 (C++代码)浏览:756 |
C语言考试练习题_保留字母 (C语言代码)浏览:670 |