티스토리 뷰
반응형
백준 1269번 대총 차집합
https://www.acmicpc.net/problem/1269
1269번: 대칭 차집합
첫째 줄에 집합 A의 원소의 개수와 집합 B의 원소의 개수가 빈 칸을 사이에 두고 주어진다. 둘째 줄에는 집합 A의 모든 원소가, 셋째 줄에는 집합 B의 모든 원소가 빈 칸을 사이에 두고 각각 주어
www.acmicpc.net


정답 코드
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
set<int>input1;
set<int>input2;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m;
cin>>n>>m;
for(int x=0;x<n;x++){
int a;
cin>>a;
input1.insert(a);
}
for(int x=0;x<m;x++){
int a;
cin>>a;
input2.insert(a);
}
int first = 0;
set<int>::iterator iter;
for (iter = input1.begin(); iter != input1.end(); iter++) {
if (input2.find(*iter) == input2.end()) {
first++;
}
}
int second = 0;
for (iter = input2.begin(); iter != input2.end(); iter++) {
if (input1.find(*iter) == input1.end()) {
second++;
}
}
cout << first + second;
}
문제 풀이
자료구조 set을 이용하여 풀 수 있는 문제입니다. set은 중복을 허용하지 않는 특성을 가지고 있습니다. 두 개의 set을 각각 빼줘서 나온 개수를 더해주면 됩니다.
반응형
'Algorithm > BOJ' 카테고리의 다른 글
백준 1308번 C++ (0) | 2023.07.23 |
---|---|
백준 1271번 Python (0) | 2023.07.23 |
백준 1260번 C++ (0) | 2023.07.22 |
백준 1259번 C++ (0) | 2023.07.22 |
백준 1251번 C++ (0) | 2023.07.22 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 알고리즘
- html
- 스택
- js
- DFS
- 유클리드 호제법
- C++
- 투 포인터
- 세그먼트 트리
- 자바스크립트
- 이분 매칭
- 자바
- BFS
- DP
- 백준
- 백준 풀이
- C++ Stack
- 반복문
- 우선순위 큐
- c++ string
- 알고리즘 공부
- Do it!
- CSS
- 자료구조
- java
- 에라토스테네스의 체
- 카운팅 정렬
- 유니온 파인드
- HTML5
- 스프링 부트 crud 게시판 구현
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함