Algorithm/BOJ

C#) [BOJ] 1940 주몽

HSH12345 2023. 1. 20. 15:29

1940번: 주몽 (acmicpc.net)

 

1940번: 주몽

첫째 줄에는 재료의 개수 N(1 ≤ N ≤ 15,000)이 주어진다. 그리고 두 번째 줄에는 갑옷을 만드는데 필요한 수 M(1 ≤ M ≤ 10,000,000) 주어진다. 그리고 마지막으로 셋째 줄에는 N개의 재료들이 가진 고

www.acmicpc.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace _230120_1
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
            StringBuilder sb0 = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();

            int N = int.Parse(sb0.Append(sr.ReadLine()).ToString());
            int M = int.Parse(sb1.Append(sr.ReadLine()).ToString());

            
            string[] arr = sr.ReadLine().Split(' ');
            int[] nums = new int[N];
            for(int i = 0; i < arr.Length; i++)
            {
                nums[i] = int.Parse(arr[i]);               
            }

            int cnt = 0;

            for(int i = 0; i < N; i++)
            {
                for(int j = N - 1; j > i; j--)
                {
                    if(nums[i] + nums[j] == M)
                    {
                        cnt++;
                    }
                }
            }

            sw.WriteLine(cnt);

            sr.Close();
            sw.Flush();
            sw.Close();

        }
    }
}

정답..