-- 예전 기록/BOJ

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

rejo 2023. 9. 8. 09:29

문제

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

입력

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

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

출력

각 테스트 케이스마다 "Case #x: A + B = C" 형식으로 출력한다. x는 테스트 케이스 번호이고 1부터 시작하며, C는 A+B이다.

풀이 과정

A + B 프로그램에서 Case #x: A + B = C 로 출력하는 기능을 추가하는 문제이다.

C

#include <stdio.h>

int main(void) {
    int t; scanf("%d", &t);
    for (int i = 1; i <= t; i++) {
        int a, b; scanf("%d %d", &a, &b);
        printf("Case #%d: %d + %d = %d\n", i, a, b, a + b);
    }
    return 0;
}

C++

#include <iostream>
using namespace std;

int main(void) {
	int t; cin >> t;
	
	for (int i = 1; i <= t; i++) {
		int a, b; cin >> a >> b;
		cout << "Case #" << i << ": " << a << " + " << b << " = " << a + b << endl;
	}
	return 0;
}

Python

import sys
input = sys.stdin.readline

t = int(input().rstrip())
for i in range(1, t+1):
    a, b = map(int, input().rstrip().split())
    print('Case #%d: %d + %d = %d'%(i, a, b, a + b))

Java

import java.util.*;

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

        for (int i = 1; i <= t; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println("Case #" + i + ": " + a + " + " + b + " = " + (a+b));
        }
    }
}