2024-03-27 23:31:28

 

A와 B의 길이와 원소들이 주어지고, A-B 차집합, B-A 차집합의 개수의 합을 출력해 주면 된다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.IO;
using System.Text;
using System.Linq;
using System.Reflection.PortableExecutable;
 
namespace 연습장
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using var reader = new StreamReader(Console.OpenStandardInput());
            using var print = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb = new StringBuilder();
 
            int[] NM = Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
 
            int[] A = Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
            int[] B = Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
 
            HashSet<int> SetA = new HashSet<int>(A);
            HashSet<int> SetB = new HashSet<int>(B);
 
            int res = 0;
 
            foreach (int i in B)
            {
                if (!SetA.Contains(i))
                    res += 1;
            }
            foreach (int j in A)
                if (!SetB.Contains(j))
                    res += 1;
 
            print.WriteLine(res);
        }
    }
}
cs

 

A와 B를 인수로 줘서 각각 해시셋을 만든다. 이후 A, B를 돌면서 해시 셋에 포함되는 게 없으면 결괏값에 1씩 추가해 주고 마지막에 출력해 주면 된다