C~K's class

Problem Description
After unremitting efforts, C~K finally became the head teacher.
Now he wants to count the list of students in the class, but C~K has a problem when exporting the class list in the educational administration system, and finds that there are some duplicate information of classmates. Now he wants to delete the duplicate information of classmates and keep only one,
but The workload is too much, so I found you who can program, can you help him solve this problem?

Enter an N in the first line of Input
, which means that the list derived from C~K has a total of N lines (N<100000).
In the next N lines, each line includes the information of a classmate, student number, name, age and gender.

The first line of Output
outputs an n, which represents the number of people in the C~K class after the duplicate names are removed.
The next n lines output the information of each classmate, and the output is in the order of input.

Sample Input
6
0001 MeiK 20 M
0001 MeiK 20 M
0002 sdk2 21 M
0002 sdk2 21 M
0002 sdk2 21 M
0000 blf2 22 F
Sample Output
3
0001 MeiK 20 M
0002 sdk2 21 M
0000 blf2 22 F

package pp;

import java.util.*;

class Person{
    String son, name, sex;
    int age;
    public Person(String son, String name,  int age, String sex) {//顺序不能错
        super();
        this.son = son;
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + age;
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((sex == null) ? 0 : sex.hashCode());
        result = prime * result + ((son == null) ? 0 : son.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Person other = (Person) obj;
        if (age != other.age)
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (sex == null) {
            if (other.sex != null)
                return false;
        } else if (!sex.equals(other.sex))
            return false;
        if (son == null) {
            if (other.son != null)
                return false;
        } else if (!son.equals(other.son))
            return false;
        return true;
    }
    public String toString() {
        return son + " " + name + " " + age + " " + sex;
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();//几个人
            List<Person>  list = new ArrayList<Person>();

            while(n-- != 0) {
                String son = sc.next();
                String name = sc.next();
                int age = sc.nextInt();
                String sex = sc.next();
                    Person p = new Person(son, name, age, sex);
                    if(!list.contains(p))//排除重复元素
                    {
                        list.add(p);
                    }
            }

            System.out.println(list.size());//个数
            Iterator<Person> it = list.iterator();
            while(it.hasNext()) {
                System.out.println(it.next());
            }

        }
        sc.close();
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324462312&siteId=291194637