๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๋ฐฑ์ค€

[๋ฐฑ์ค€/Java] 11382 ๊ผฌ๋งˆ ์ •๋ฏผ : ๋Ÿฐํƒ€์ž„์—๋Ÿฌ

by ๋ฝ€์งœ๊ผฌ 2025. 1. 14.
728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

๊ผฌ๋งˆ ์ •๋ฏผ์ด๋Š” ์ด์ œ A + B ์ •๋„๋Š” ์‰ฝ๊ฒŒ ๊ณ„์‚ฐํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด์ œ A + B + C๋ฅผ ๊ณ„์‚ฐํ•  ์ฐจ๋ก€์ด๋‹ค!

์ž…๋ ฅ

์ฒซ ๋ฒˆ์งธ ์ค„์— A, B, C (1 ≤ A, B, C ≤ 10^12)์ด ๊ณต๋ฐฑ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ

A+B+C์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.


๋ถ„๋ช… ๋งž๋Š” ์ฝ”๋“œ๋ฅผ ์ œ์ถœํ–ˆ๋Š”๋ฐ ์™œ ๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€ ๋‚˜์ง€??

 

ํ–ˆ๋Š”๋ฐ ๋‹ต์€ ๋ฌธ์ œ์— ์žˆ์—ˆ๋‹ค.

A, B, C๋Š” ์ตœ๋Œ€ 10์˜ 12์Šน์ด๋ฏ€๋กœ int๊ฐ€ ์•„๋‹ˆ๋ผ

 long ํƒ€์ž…์— ์ €์žฅํ•ด์•ผํ•œ๋‹ค.

 

๋‚˜๋Š” Scanner ๋ฌธ์ œ์ธ๊ฐ€.. ํ•ด์„œ ๋ฒ„ํผ๋กœ๋„ ๋ฐ”๊ฟ”๋ดค๋Š”๋ฐ..

๊ทธ๋ƒฅ ํƒ€์ž… ๋ฌธ์ œ์˜€๋˜๊ฑธ๋ฃจ.

 

 

์œ„๊ฐ€ ์Šค์บ๋„ˆ๊ณ , ์•„๋ž˜๊ฐ€ ๋ฒ„ํผ์ด๋‹ค. ํ™•์‹คํžˆ ์†๋„ ์ฐจ์ด๊ฐ€ ๋ณด์ธ๋‹ค.

(์ด๊ฑฐ์— ๊ด€ํ•œ ๊ณ ์ฐฐ์€ ๋‹ค์Œ ํฌ์ŠคํŒ…์— ์˜ฌ๋ฆฌ๋Š”๊ฑธ๋กœ)

 

1. BufferedReader

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        //์ด๋ฒˆ์—” ํ† ํฐ์„ ์จ๋ณด์ž
        StringTokenizer st = new StringTokenizer(input);
        long A = Long.parseLong(st.nextToken());
        long B = Long.parseLong(st.nextToken());
        long C = Long.parseLong(st.nextToken());

        System.out.println(A+B+C);
    }
}

2. Scanner

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();

        System.out.println(A+B+C);

    }
}
728x90
๋ฐ˜์‘ํ˜•