문제 링크: https://www.acmicpc.net/problem/10951
백준 반복문 11단계 - 10951번 A+B - 4를 풀어보았다.
풀이: 입력을 받는 한 동작하게 하면 된다.
파이썬의 경우, try except를 사용했다.
C++
#include <iostream>
using namespace std;
int main()
{
int a,b;
while(cin >> a>>b) // 입력이 들어오는 한 동작
{
cout<<a+b<<"\n";
}
}
Python
while 1:
try:
a,b=map(int,input().split())
print(a+b)
except:
break
Java
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt())
{
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a+b);
}
sc.close();
}
}
'코테용 문제풀이 > 백준' 카테고리의 다른 글
개수 세기 풀이 (0) | 2022.12.31 |
---|---|
더하기 사이클 풀이 (0) | 2022.12.31 |
A+B - 5 풀이 (0) | 2022.12.31 |
별 찍기 - 2 풀이 (0) | 2022.12.31 |
A+B - 8 풀이 (0) | 2022.12.31 |