🔗문제 풀러가기
단계별로 풀어보기 단계 14의 1번째 문제이다.
Set 컨네이너를 이용해 문제를 해결하였다.
#include <iostream>
#include <set>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
set<int> _set;
cin >> n;
for (int i = 0; i < n; i++)
{
int input;
cin >> input;
_set.insert(input);
}
cin >> m;
for (int i = 0; i < m; i++)
{
int input;
cin >> input;
if (_set.find(input) != _set.end())
{
cout << "1 ";
}
else
{
cout << "0 ";
}
}
}
_set.find(input)을 하였을 때 _set에 input이 없다면
_set.end()가 반환된다.