Fare丶梦


私信TA

用户名:126913199

访问量:31074

签 名:

等  级
排  名 134
经  验 4890
参赛次数 0
文章发表 50
年  龄 22
在职情况 学生
学  校
专  业

  自我简介:

解题思路:





注意事项:

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 人评分

  评论区