01-25 03:45
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 10824 :: ๋„ค์ˆ˜ JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ 10824 :: ๋„ค์ˆ˜ JAVA

miinsun 2022. 3. 15. 20:17

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

๋„ค ์ž์—ฐ์ˆ˜ A, B, C, D๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, A์™€ B๋ฅผ ๋ถ™์ธ ์ˆ˜์™€ C์™€ D๋ฅผ ๋ถ™์ธ ์ˆ˜์˜ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

๋‘ ์ˆ˜ A์™€ B๋ฅผ ํ•ฉ์น˜๋Š” ๊ฒƒ์€ A์˜ ๋’ค์— B๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. ์ฆ‰, 20๊ณผ 30์„ ๋ถ™์ด๋ฉด 2030์ด ๋œ๋‹ค.

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— ๋„ค ์ž์—ฐ์ˆ˜ A, B, C, D๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ A, B, C, D ≤ 1,000,000)

 

์ถœ๋ ฅ

  • A์™€ B๋ฅผ ๋ถ™์ธ ์ˆ˜์™€ C์™€ D๋ฅผ ๋ถ™์ธ ์ˆ˜์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

10 20 30 40

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

4060

 

 

๐Ÿ’ป  Main.java

  •  ๋ฌธ์ž์—ด s1, s2๋ฅผ ์ „๋ถ€ ํ•ฉ์น˜๋ฉด int ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚˜๊ธฐ ๋•Œ๋ฌธ์— answer๋ฅผ long์œผ๋กœ ์ง€์ •ํ•ด์ค˜์•ผํ•œ๋‹ค
    • answer๋ฅผ intํ˜•์œผ๋กœ ์„ค์ •ํ•  ์‹œ, numberFormat Error๊ฐ€ ๋ฐœ์ƒ
/* ๋ฐฑ์ค€ ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ - 10824 :: ๋„ค ์ˆ˜ */
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long answer = 0;
		for(int i = 0; i < 2; i++) {
			String s1 = sc.next();
			String s2 = sc.next();
			
			answer += Long.parseLong(s1 + s2);
		}

		System.out.println(answer);
		sc.close();
	}
}
Comments