코테 2023. 3. 10. 03:34

전체 코드

#include <iostream>

int main()
{
	int A, B;
	
	while (true)
	{
		std::cin >> A >> B;
		if (std::cin.eof())
			break;
		std::cout << A + B << std::endl;
	}
}

 

풀이

  • 백준 10952 A+B -5 문제랑 거의 유사함(변형식으로 풂)
  • 무한반복 조건문
  • 먼저 A와 B를 입력받음
  • std::cin.eof()를 이용해 eof가 감지되었다면 break해 반복문 탈출후 종료
  • if문에 안걸렸다면 A+B출력후 다시 반복 
while (true)
{
	std::cin >> A >> B;
	if (std::cin.eof())
		break;
	std::cout << A + B << std::endl;
}
  • 종료 조건이 안적혀 있었으므로 문제 설명 참조해서 EOF를 이용함