14425문자열 집합

LJM·2023년 1월 6일
0

백준풀기

목록 보기
17/259

https://www.acmicpc.net/problem/14425

해시셋 이용해서 금방 해결!

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {

        FastReader fr = new FastReader();

        String[] MN = fr.nextLine().split(" ");
        int M = Integer.parseInt(MN[0]);
        int N = Integer.parseInt(MN[1]);

        HashSet<String> mlist = new HashSet<>();
        for(int i = 0; i < M; ++i)
        {
            mlist.add(fr.nextLine());
        }

        int result = 0;
        for(int i = 0; i < N; ++i)
        {
            if(mlist.contains(fr.nextLine()))
                result++;
        }

        System.out.println(result);
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    FastReader()
    {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next()
    {
        while(st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch(IOException e)
            {
                e.printStackTrace();
            }

        }
        return st.nextToken();
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

}
profile
게임개발자 백엔드개발자

0개의 댓글