解题思路:
注意事项:
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分
0 人评分
点我有惊喜!你懂得!浏览:1424 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:369 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:396 |
C语言考试练习题_排列 (C++代码)浏览:509 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:418 |
简单的a+b (C语言代码)浏览:420 |
C语言程序设计教程(第三版)课后习题9.8 (Java代码)浏览:1276 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:480 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:543 |
1048题解(读入回车问题)浏览:470 |