์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step4] 10952 : A+B - 5 (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 7. 21:51

www.acmicpc.net/problem/10952

 

10952๋ฒˆ: A+B - 5

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

www.acmicpc.net


๋ฌธ์ œ

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

 

์ž…๋ ฅ

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ฐ ์ค„์— A์™€ B๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (0 < A, B < 10)

์ž…๋ ฅ์˜ ๋งˆ์ง€๋ง‰์—๋Š” 0 ๋‘ ๊ฐœ๊ฐ€ ๋“ค์–ด์˜จ๋‹ค.

 

์ถœ๋ ฅ

๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋งˆ๋‹ค A+B๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ

1 1

2 3

3 4

9 8

5 2

0 0

 

์˜ˆ์ œ ์ถœ๋ ฅ

2

5

7

17

7


ํ’€์ด

1. while๋กœ ๋ฌดํ•œ๋ฃจํ”„๋ฅผ ๋งŒ๋“ค์–ด a์™€ b๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

2. if๋ฌธ์„ ์ด์šฉํ•˜์—ฌ a์™€ b๊ฐ€ ๋‘˜ ๋‹ค 0์ธ์ง€ ํ™•์ธํ•˜๊ณ  ๋‘˜ ๋‹ค 0์ผ๋•Œ๋งŒ break ํ•œ๋‹ค.

3. a+b ๊ฐ’์„ write() ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฒ„ํผ์— ์ถœ๋ ฅํ•œ๋‹ค.

4. while๋ฌธ์„ ํƒˆ์ถœํ•œ ํ›„์— ๋ฒ„ํผ์— ๋‚จ์€ ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

import java.io.*;
import java.util.StringTokenizer;

public class B10952 {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		while(true) {
			
			StringTokenizer st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());

			if(a == 0 && b == 0) {
				break;
			}
			bw.write( a+b + "\n");
		}
		
		bw.flush();
		bw.close();

	}

}