CSE/baekjoon & swexpert
백준 14425 문자열집합 ] 자료구조 HashSet 이용! (Set)
언제나 변함없이
2019. 4. 13. 20:54
반응형
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int makeSet = sc.nextInt();
int testCase = sc.nextInt();
int result = 0;
sc.nextLine(); //남아있는 개행문자를 제거하기 위해 추가함!
//HashSet을 문자열로 만듭니다.
HashSet<String> hs1 = new HashSet<String>();
for(int i = 0 ; i < makeSet; i++) {
hs1.add(sc.nextLine());
}
for(int i = 0 ; i < testCase; i++) {
String get = sc.nextLine();
if(hs1.contains(get)) result++;
}
System.out.println(result);
}
}
참고링크
https://hackersstudy.tistory.com/26
https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html
http://tcpschool.com/java/java_collectionFramework_set
반응형