본문 바로가기
알고리즘/백준

[Python/Java] 백준 2588번 - 곱셈

by 소꿍 2020. 6. 8.

https://www.acmicpc.net/problem/2588

 

2588번: 곱셈

첫째 줄부터 넷째 줄까지 차례대로 (3), (4), (5), (6)에 들어갈 값을 출력한다.

www.acmicpc.net

 

Python

 

a = input()
b = input()

c = int(a) * int(b[len(b)-1])
d = int(a) * int(b[len(b)-2])
e = int(a) * int(b[len(b)-3])
triple_mult = c*1 + d*10 + e*100

print(c, d, e, triple_mult, sep='\n')

Java

 

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n1 = scan.nextInt();
		int n2 = scan.nextInt();

		int m1 = n2 % 10;
		int m2 = (n2 % 100) / 10;
		int m3 = n2 / 100;

		
		int r1 = n1 * m1;
		int r2 = n1 * m2;
		int r3 = n1 * m3;

		System.out.println(r1);
		System.out.println(r2);
		System.out.println(r3);
		System.out.println(r1 + (r2 * 10) + (r3 * 100));
		
		scan.close();

	}

}

댓글