解题思路:
注意事项:
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 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:562 |
简单的a+b (C语言代码)浏览:676 |
C语言训练-排序问题<2> (C++代码)浏览:872 |
A+B for Input-Output Practice (C++代码)浏览:604 |
【数组的距离】 (C语言代码)浏览:728 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:593 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
【金明的预算方案】 (C++代码)浏览:834 |
母牛的故事 (C语言代码)浏览:710 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:682 |