배열 한접시

[백준] 두 수의 합 [C#]

NaZZU 2024. 4. 19. 00:27

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace 연습장
{
    internal class _3273_boj
    {
        public void boj_3273()
        {
            int n = int.Parse(Console.ReadLine());
 
            int[] input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
 
            List<int> arr = new List<int>();
 
            for (int i = 0; i < n; i++)
                arr.Add(input[i]);
 
            int x = int.Parse(Console.ReadLine());
 
            int res = 0;
            for (int i = 0; i < n; i++)
            {
                if (arr[i] == x - arr[i])
                    continue;
                if (arr.Contains(x - arr[i]))
                    res++;
            }
 
            Console.WriteLine(res / 2);
        }
 
    }
}
 
cs

 

최대한 배열로 풀어보려고 했는데, 못해먹겠어서 리스트를 이용해서 해결했다.