๊ธฐ๋ก๋ฐฉ

BOJ_10757 : ํฐ ์ˆ˜ A+B ๋ณธ๋ฌธ

CodingTest/Java

BOJ_10757 : ํฐ ์ˆ˜ A+B

Soom_1n 2023. 1. 12. 10:12

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

10757๋ฒˆ: ํฐ ์ˆ˜ A+B

๋‘ ์ •์ˆ˜ A์™€ B๋ฅผ ์ž…๋ ฅ๋ฐ›์€ ๋‹ค์Œ, A+B๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • longํ˜•์˜ ํฌ๊ธฐ๋ฅผ ๋„˜๋Š” ์•„์ฃผ ํฐ ์ˆ˜ A, B๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.
  • java์˜ ํฐ์ˆ˜ ์ฒ˜๋ฆฌ๋Š” BigIntegerํ˜•์„ ๋งŒ๋“ค์–ด ์ฒ˜๋ฆฌํ•œ๋‹ค.
    • BigInteger๋Š” ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„์ฃผ ํฐ ์ˆ˜๋„ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅํ•˜๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger a = new BigInteger(sc.next());
		BigInteger b = new BigInteger(sc.next());
		System.out.println(a.add(b));
	}
}

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • BigInteger๋กœ a์™€ b์— ์ž…๋ ฅ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•ด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  • BigInteger์˜ ํ•ฉ์„์œ„ํ•ด add๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ’์„ ๋”ํ•ด ๋ฐ”๋กœ ์ถœ๋ ฅํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • BigInteger๋งŒ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ์•„์ฃผ ์†์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€๋‹ค.

728x90