소지하고 있는 숫자 카드인지를 판별하는 문제입니다.
간단하게 hash 자료구조인 map을 활용해 저장했고, key와 key값은 소지의 유무에대해 저장했습니다.
저장된 key값에 소지의 유무에 따라 답을 출력합니다.
#include<iostream>
#include<map>
using namespace std;
map<int, int>_map;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N, M = 0;
cin >> N;
for (int i = 0;i < N;i++)
{
int _temp = 0;
cin >> _temp;
_map.insert({ _temp,1 });
}
cin >> M;
for (int i = 0;i < M;i++)
{
int _temp = 0;
cin >> _temp;
map<int, int>::iterator iter = _map.find(_temp);
if (iter != _map.end())
{
cout << (*iter).second << ' ';
}
else
{
cout << 0 << ' ';
}
}
return 0;
}