Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AV-Un3G64SUDFAXr&categoryId=AV-Un3G64SUDFAXr&categoryType=CODE&problemTitle=&orderBy=INQUERY_COUNT&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=13 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 


๊ทธ๋ƒฅ ํ•ด์‰ฌ๋งต๋งŒ ์ด์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

 

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int a=kb.nextInt();
            int b=kb.nextInt();
            String[] arr1=new String[a];
            String[] arr2=new String[b];
            for(int i=0; i<a; i++) arr1[i]=kb.next();
            for(int i=0; i<b; i++) arr2[i]=kb.next();
            
            HashMap<String, Integer> map=new HashMap<>();
            for(String x:arr1){
                map.put(x,map.getOrDefault(x,0)+1);
            }
            
            int cnt=0;
            for(String x:arr2){
                if(map.containsKey(x))
                    cnt++;
            }
            System.out.println("#"+t+" "+cnt);
        }
    }
}