C++/Baekjoon

백준 10951: A+B - 4

RIsN 2022. 7. 18. 21:26

문제

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


입력

입력은 여러 개의 테스트 케이스로 이루어져 있다.

각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)


출력

각 테스트 케이스마다 A+B를 출력한다.


코드

#include <iostream>

using namespace std;

int main()
{
    // :: 입력 및 연산
    string textContainer = "";
    while(true) {
        // :: 입력
        int a, b;
        
        // :: EXIT : 마지막 라인일 때
        if((cin >> a >> b).eof()) break;
        
        // :: 개행 입력
        if(textContainer != "") textContainer += "\n";
        
        // :: 연산 추가
        textContainer += to_string(a + b);
    }
    
    // :: 출력
    cout << textContainer;

    return 0;
}

참고