숫자 카드는 정수 하나가 적혀져 있는 카드이다. 상근이는 숫자 카드 N개를 가지고 있다. 정수 M개가 주어졌을 때, 이 수가 적혀있는 숫자 카드를 상근이가 가지고 있는지 아닌지를 구하는 프로그램을 작성하시오.
같은 카드는 없다.
주어진 입력인 N,M (int)가 모두 크기 때문에 이 점을 유의해야한다.
주어진 N개의 카드의 수를 맵에 추가해준 뒤,
맵 검색을 이용하여 M개의 카드를 찾고, 있다면 1을, 없다면 0을 출력하도록 한다.
딱히 Value값은 이용하지 않기 때문에 0으로 해둔다.
입력이 int형으로 정해져있기 때문에, strong type을 사용하는 Dictionary 자료구조를 사용했다.
namespace SongE
{
public class Program
{
static void Main(string[] args)
{
using var input = new System.IO.StreamReader(Console.OpenStandardInput());
using var print = new System.IO.StreamWriter(Console.OpenStandardOutput());
int n = int.Parse(input.ReadLine());
int[] nCard = Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
Dictionary<int, int> ht = new();
for (int i = 0; i < n; i++)
{
ht.Add(nCard[i], 0);
}
int m = int.Parse(input.ReadLine());
int[] mCard = Array.ConvertAll(input.ReadLine().Split(), s => int.Parse(s));
for (int i = 0; i < m; i++)
{
if (ht.ContainsKey(mCard[i]))
{
print.Write($"{1} ");
}
else
{
print.Write($"{0} ");
}
}
}
}
}