문제 링크: https://www.acmicpc.net/problem/10952
백준 반복문 10단계 - 10952번 A+B - 5를 풀어보았다.
풀이: 빠져나오는 조건이 있는 무한루프를 만들면 된다.
C++
#include <iostream>
using namespace std;
int main()
{
int a,b;
while(1)
{
cin>>a>>b;
if(a==0&&b==0) break;
cout<<a+b<<"\n";
}
}
Python
while 1:
a,b=map(int,input().split())
if(a==0 and b==0): break
print(a+b)
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while(true)
{
int a = sc.nextInt();
int b = sc.nextInt();
if(a==0&&b==0) break;
System.out.println(a+b);
}
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
더하기 사이클 풀이 (0) | 2022.12.31 |
---|---|
A+B - 4 풀이 (0) | 2022.12.31 |
별 찍기 - 2 풀이 (0) | 2022.12.31 |
A+B - 8 풀이 (0) | 2022.12.31 |
A+B - 7 풀이 (0) | 2022.12.31 |