Notice
Recent Posts
Recent Comments
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

백준[Java] 11022번 A+B-8 본문

IT/Java[백준]

백준[Java] 11022번 A+B-8

빌드이너프 2023. 2. 20. 16:09

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

 

11022번: A+B - 8

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

www.acmicpc.net

문제풀이 1

import java.util.Scanner;
public class _11022_1 {
    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.printf("Case #%d: %d + %d = %d%n", i, A, B, A+B);
        }
        sc.close();
    }
}

문제풀이 2

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class _11022_2 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());

        for (int i = 1; i <= T; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            System.out.printf("Case #%d: %d + %d = %d%n", i, A, B, A+B);
        }
        br.close();
    }
}

문제풀이 3

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class _11022_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());

        for (int i = 1; i <= T; i++) {
            String[] str = br.readLine().split(" ");
            int A = Integer.parseInt(str[0]);
            int B = Integer.parseInt(str[1]);
            System.out.printf("Case #%d: %d + %d = %d%n", i, A, B, A+B);
        }
        br.close();
    }
}

문제풀이 4

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class _11022_4 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());

        StringBuilder sb = new StringBuilder();
        StringTokenizer st;

        for (int i = 1; i <= T; i++) {
            st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            sb.append("Case #" + i + ": ").append(A + " + " + B + " = " + (A+B)).append('\n');
        }
        br.close();
        System.out.println(sb);
    }
}

문제풀이 5

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

public class _11022_5 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int T = Integer.parseInt(br.readLine());

        StringBuilder sb = new StringBuilder();
        StringTokenizer st;

        for (int i = 1; i <= T; i++) {
            st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            bw.write("Case #"+i+": ");
            bw.write(A + " + " + B + " = ");
            bw.write((A+B) + "\n");
        }
        br.close();
        bw.flush();
        bw.close();
    }
}

문제풀이 6

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class _11022_6 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(br.readLine());

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= T; i++) {
            String str  = br.readLine();
            int A = str.charAt(0)-'0';
            int B = str.charAt(2)-'0';
            sb.append("Case #").append(i).append(": ").append(A)
                    .append(" + ").append(B).append(" = ").append(A+B).append('\n');
        }
        System.out.println(sb);
    }
}