[백준, BOJ 1269] 대칭 차집합 (java)
Problem Solving/BOJ

[백준, BOJ 1269] 대칭 차집합 (java)

728x90

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

메모리: 83,196 KB , 시간: 724 ms

사용 알고리즘: 자료 구조, 해시를 사용한 집합과 맵

728x90

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        st = new StringTokenizer(br.readLine());
        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());

        Set<Integer> aSet = new HashSet<>();
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < A; i++) {
            aSet.add(Integer.parseInt(st.nextToken()));
        }

        Set<Integer>  bSet = new HashSet<>();
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < B; i++) {
            bSet.add(Integer.parseInt(st.nextToken()));
        }

        int count = 0;
        for (int b : bSet) { // A - B
            if(!aSet.contains(b)) count++;
        }
        for (int a : aSet) { // B - A
            if(!bSet.contains(a)) count++;
        }

        System.out.println(count);
    }
}
728x90