/* 종이 자르기
* 머쓱이는 큰 종이를 1 x 1 크기 +로 자르려고 합니다.
* 예를 들어 2 x 2 크기의 종이를 1 x 1 크기로 자르려면 최소 가위질 세 번이 필요합니다
* 정수 M, N이 매개변수로 주어질 때, M x N 크기의 종이를 최소로 가위질 해야하는 횟수를 return 하도록 solution 함수를 완성해보세요.
*
* M N result
* 2 2 3
* 2 5 9
* 1 1 0
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | public class programmer_0_4 { static int m1 = 2; static int n1 = 2; static int m2 = 2; static int n2 = 5; static int m3 = 1; static int n3 = 1; public int solution(int M, int N){ //가로, 세로 int answer = 0; if(M == N) N = N * (M-1); else N = (N-1) * M; M = M - 1; answer = N + M; return answer; } public static void main(String args[]){ programmer_0_4 t = new programmer_0_4(); System.out.println("result = " + t.solution(m1,n1)); System.out.println("---------------------------------------"); System.out.println("result2 = " + t.solution(m2,n2)); System.out.println("---------------------------------------"); System.out.println("result3 = " + t.solution(m3,n3)); System.out.println("---------------------------------------"); } } | cs |