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

[BOJ/Step1] 2588 : ๊ณฑ์…ˆ (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 6. 17:19

www.acmicpc.net/problem/2588

 

2588๋ฒˆ: ๊ณฑ์…ˆ

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ ๋„ท์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ (3), (4), (5), (6)์— ๋“ค์–ด๊ฐˆ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net


๋ฌธ์ œ

(์„ธ ์ž๋ฆฌ ์ˆ˜) × (์„ธ ์ž๋ฆฌ ์ˆ˜)๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ํ†ตํ•˜์—ฌ ์ด๋ฃจ์–ด์ง„๋‹ค.

(1)๊ณผ (2)์œ„์น˜์— ๋“ค์–ด๊ฐˆ ์„ธ ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ (3), (4), (5), (6)์œ„์น˜์— ๋“ค์–ด๊ฐˆ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— (1)์˜ ์œ„์น˜์— ๋“ค์–ด๊ฐˆ ์„ธ ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๊ฐ€, ๋‘˜์งธ ์ค„์— (2)์˜ ์œ„์น˜์— ๋“ค์–ด๊ฐˆ ์„ธ์ž๋ฆฌ ์ž์—ฐ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

 

์ถœ๋ ฅ

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ charc๋„ท์งธ ์ค„๊นŒ์ง€ ์ฐจ๋ก€๋Œ€๋กœ (3), (4), (5), (6)์— ๋“ค์–ด๊ฐˆ ๊ฐ’์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

472

385

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

2360

3776

1416

181720


ํ’€์ด

1. int num1, num2 ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค.

2. num2๋ฅผ String์œผ๋กœ ํ˜•๋ณ€ํ™˜ ํ•œ๋‹ค.

3. num2์„ ๋ถ„ํ•ดํ•˜์—ฌ char a, b, c์— ๊ฐ๊ฐ ์ผ์˜์ž๋ฆฌ์ˆ˜, ์‹ญ์˜์ž๋ฆฌ์ˆ˜, ์‹ญ์˜์ž๋ฆฌ์ˆ˜๋ฅผ ์ €์žฅํ•œ๋‹ค.

   => charAt() ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ

4. a, b, c๋ฅผ Intํ˜•์œผ๋กœ ํ˜•๋ณ€ํ™˜ํ•˜์—ฌ num1 * a, num1 * b, num1 * c, num1 * num2 ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

   => getNumericValue() ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ

 

import java.util.Scanner; 

public class B2588 { 

	public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in); 
		int num1 = sc.nextInt(); 
		int num2 = sc.nextInt(); 
		multi(num1,num2); 
    } 
    
	public static void multi(int num1, int num2) { 
		
        String num = Integer.toString(num2); 
		
        char a = num.charAt(2); 
		char b = num.charAt(1); 
		char c = num.charAt(0); 
		
        System.out.println(num1 * Character.getNumericValue(a)); 
		System.out.println(num1 * Character.getNumericValue(b)); 
		System.out.println(num1 * Character.getNumericValue(c)); 
		System.out.println(num1 * num2); 
        
        return; 
	} 
}