-- 예전 기록/BOJ

[ BOJ ] 10952 : A+B - 5 ( BRONZE 5 ) / C, C++, Python, Java

rejo 2023. 9. 8. 09:44

문제

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

입력

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

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

입력의 마지막에는 0 두 개가 들어온다.

출력

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

풀이 과정

테스트 케이스가 미리 주어지지 않고, 입력의 마지막에 0 두 개가 입력으로 들어온다.

0 두 개가 입력으로 들어오기 전까지 A + B 를 출력하면 되는 문제이다.

C

#include <stdio.h>

int main(void) {
    while(1) {
        int a, b; scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) break;
        printf("%d\n", a + b);
    }
    return 0;
}

C++

#include <iostream>
using namespace std;

int main(void) {
	while(1) {
		int a, b; cin >> a >> b;
		if (a == 0 && b == 0) break;
		cout << a + b << endl;
	}
	return 0;
}

Python

import sys
input = sys.stdin.readline

while True:
    a, b = map(int, input().split())
    if a == b == 0: break
    print(a+b)

Java

import java.util.*;

public 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);
        }
    }
}