백준/10815/자료구조/숫자 카드

유기태·2023년 12월 31일

백준/10815/자료구조/숫자 카드

문제 해석

소지하고 있는 숫자 카드인지를 판별하는 문제입니다.

문제 풀이

간단하게 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;
}
profile
게임프로그래머 지망!

0개의 댓글