C#/알고리즘

백준#10951 - A+B - 4

McRobbin 2020. 4. 8. 10:01

https://www.acmicpc.net/problem/10951

 

10951번: A+B - 4

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

while문으로 분류된 문제입니다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _10951
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (input == null)
                    break;
                Console.WriteLine(int.Parse(input.Split(' ')[0]) + int.Parse(input.Split(' ')[1]));
            }
        }
    }
}
 
 
 

 

10952문제와 유사하지만 끝나는 지점이 따로 있지 않습니다. 무한 반복으로 입력을 받으며

입력받은 string값이 null일 때 (아무것도 들어오지 않았을 때) 종료되도록 했습니다.