Machineboy空

백준 10951: A+B - 4 (while문 활용) 입력값 마지막 줄까지 읽는 법 본문

카테고리 없음

백준 10951: A+B - 4 (while문 활용) 입력값 마지막 줄까지 읽는 법

안녕도라 2023. 9. 6. 20:29
using System;
using System.Text;

namespace CodingTestForBaekJoon
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string input = Console.ReadLine();

                if (input == null)
                {
                    break;
                }

                string[] cases = input.Split();
                int a = int.Parse(cases[0]);
                int b = int.Parse(cases[1]);
                
                Console.WriteLine(a+b);
            }

        }       
    }
}

오답이유) 테스트 케이스가 몇 줄인지를 알아서 그만큼 반복을 한 뒤 탈출하는 코드를 잘못짰다.