[백준] 11021번 A+B – 7 풀이 코드 (C/C++/Java 자바/Python 파이썬)

by iamtrueline

풀이

출력 문자열 형태에 유의하며 for문을 이용하여 답을 출력합니다.


코드

C

#include <stdio.h>

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

C++

#include <iostream>

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

Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 1; i <= n; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int ans = a+b;
            System.out.println("Case #"+ i + ": " + ans);
        }
    }
}

Python

1
2
3
4
5
n = int(input())
for i in range(n):
    a,b = map(int, input().split())
    ans = a + b
    print("Case #%s: %s"%(i+1, ans))

문제 출처

https://www.acmicpc.net/problem/11021

You may also like

Leave a Comment

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00