Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 후니의 쉽게 쓴 시스코 네트워킹
- 이분탐색
- 동적계획법
- 스택
- CS
- 투 포인터
- 완전탐색
- 에라토스테네스의 체
- 유니온 파인드
- 그리디
- mst
- 프로그래머스
- Kotlin
- 수학
- Network
- java
- BFS
- 위상정렬
- 세그먼트 트리
- Effective Java
- 문자열
- swea
- 알고리즘
- 플로이드-와샬
- dfs
- 백준
- 백트래킹
- 구현
- 시뮬레이션
- JUnit 5
Archives
반갑습니다!
[백준] 1822 차집합 본문
풀이
집합 B를 Set
에 담고 A의 원소들을 탐색해서 답을 찾았다.
코드
C++
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n1, n2;
cin >> n1 >> n2;
vector<int> a(n1);
set<int> b;
for (int i = 0; i < n1; i++)
cin >> a[i];
for (int i = 0; i < n2; i++) {
int tmp;
cin >> tmp;
b.insert(tmp);
}
vector<int> answer;
for (int num : a) {
if (b.find(num) == b.end())
answer.push_back(num);
}
sort(answer.begin(), answer.end());
cout << answer.size() << '\n';
for (int i : answer)
cout << i << ' ';
return 0;
}
Python3
import sys
from bisect import bisect_left, bisect_right
n1, n2 = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = set(map(int, sys.stdin.readline().rstrip().split()))
answer = []
for i in a:
if i not in b:
answer.append(i)
answer.sort()
print(len(answer))
for i in answer:
print(i, end=' ')
'알고리즘 문제 풀이' 카테고리의 다른 글
[백준] 5567 결혼식 (0) | 2020.09.24 |
---|---|
[백준] 1939 중량제한 (0) | 2020.09.24 |
[백준] 1715 카드 정렬하기 (0) | 2020.09.23 |
[백준] 2012 등수매기기 (0) | 2020.09.23 |
[프로그래머스] 두 개 뽑아서 더하기 (0) | 2020.09.22 |