C~K's class (JAVA)

Class C~K
Time Limit: 1500 ms Memory Limit: 65536 KiB
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?
Input

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

The first line outputs an n, which represents how many people in the class C~K 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
Hint
Source
C~K

This question should be regarded as a water question. It seems that you need to use hashcode or something. Because I don't understand it, I just tried it.

import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        List<String> ls = new LinkedList<String>();
        input.nextLine();
        while(n-- > 0){
            String str = input.nextLine();
            if(!ls.contains(str)){
                ls.add(str);
            }
        }
        System.out.println(ls.size());
        for(int i = 0;i < ls.size();i++){
            String ss = ls.get(i);
            System.out.println(ss);
        }
        input.close();
    }
}

Guess you like

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