ALGORITHM
백준 / 1920번 / 수 찾기 / C++
chrisysl
2019. 1. 28. 20:59
# 출처 : https://www.acmicpc.net/problem/1920
정렬되어 저장해주기 때문에 따로 정렬을 할 필요가 없는 자료구조 set을 사용하여 풀었다.
# 풀이
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <set> #include <algorithm> int N, M, num; std::set<int> base; int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> N; for (int i = 0; i < N; ++i){ std::cin >> num; base.insert(num); } std::cin >> M; for (int i = 0; i < M; ++i){ std::cin >> num; std::cout << (base.find(num) == base.end() ? 0 : 1) << '\n'; } return 0; } | cs |