-- 예전 기록/BOJ

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

rejo 2023. 9. 3. 14:52

문제

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

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다.

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

출력

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

풀이 과정

들어오는 입력마다 합을 계산하여 출력하면 되는 반복문 기초 문제이다.

C

#include <stdio.h>

int main(void) {
    int t; scanf("%d", &t);

    while(t--) {
        int a, b; scanf("%d %d", &a, &b);
        printf("%d\n", a + b);
    }
    return 0;
}

C++

#include <iostream>
using namespace std;

int main(void) {
    int t; cin >> t;

    while(t--) {
        int a, b; cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Python

import sys
input = sys.stdin.readline

t = int(input().rstrip())
for _ in range(t):
    a, b = map(int, input().rstrip().split())
    print(a + b)

Java

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        for (int tidx = 0; tidx < t; tidx++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}