Notice
Recent Posts
Recent Comments
Link
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

hwooo

BOJ (C/C++) 1269번: 대칭 차집합 본문

Study/Algorithm

BOJ (C/C++) 1269번: 대칭 차집합

hwooo 2022. 11. 23. 06:02

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

 

1269번: 대칭 차집합

첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어

www.acmicpc.net


풀이

A, B 집합을 따로 받고 A에서 B의 원소가 없다면, B에서 A의 원소가 없다면 cnt++


코드

#include <stdio.h>
#include <iostream>
#include <set>
#include <string>
using namespace std;

int main() {
	int a, b, cnt = 0;
	set <string> A, B;
	string s;

	scanf("%d %d", &a, &b);
	for (int i = 0; i < a; i++) {
		cin >> s;
		A.insert(s);
	}
	for (int i = 0; i < b; i++) {
		cin >> s;
		B.insert(s);
	}

	for (auto b = B.begin(); b!=B.end(); b++) {
		if (A.find(*b) == A.end()) cnt++;
	}
	for (auto a = A.begin(); a != A.end(); a++) {
		if (B.find(*a) == B.end()) cnt++;
	}

	printf("%d", cnt);
	return 0;
}