숫자 카드는 정수 하나가 적혀져 있는 카드이다. 상근이는 숫자 카드 N개를 가지고 있다. 정수 M개가 주어졌을 때, 이 수가 적혀있는 숫자 카드를 상근이가 몇 개 가지고 있는지 구하는 프로그램을 작성하시오.
Dictionary<int,int> 를 만든다.
맵에 있는지 키값으로 찾아서 있다면 값을 증가시켜주고
없다면 페어를 추가해주는 식으로 진행한다.
해당 맵에 카드 M이 있다면 해당하는 카드의 밸류값을 출력하고,
없다면 0을 출력하도록 해준다.
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++)
{
if (ht.ContainsKey(nCard[i]))
ht[nCard[i]]++;
else ht.Add(nCard[i], 1);
}
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($"{ht[mCard[i]]} ");
}
else
{
print.Write($"{0} ");
}
}
}
}
}