/* 피자 나눠 먹기 (3)
* 피자를 두 조각에서 열 조각까지 원하는 조각 수로 잘라줍니다.
* 피자 조각 수 slice와 피자를 먹는 사람의 수 n이 매개변수로 주어질 때,
* n명의 사람이 최소 한 조각 이상 피자를 먹으려면
* 최소 몇 판의 피자를 시켜야 하는지를 return
*
* slice n result
* 7 10 2 10명이 7조각으로 자른 피자를 한 조각 이상씩 먹으려면 최소 2판
* 4 12 3 12명이 4조각으로 자른 피자를 한 조각 이상씩 먹으려면 최소 3판
*/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class programmer_0_41 { static int a1 = 7; static int b1 = 10; static int a2 = 4; static int b2 = 12; public int solution(int slice, int n) { int answer = 0; while(1==1){ answer++; if(answer * slice / n > 0) break; } return answer; } public static void main(String args[]){ programmer_0_41 t = new programmer_0_41(); System.out.println("---------------------------------------"); System.out.println("result = " + t.solution(a1,b1)); System.out.println("---------------------------------------"); System.out.println("result2 = " + t.solution(a2,b2)); System.out.println("---------------------------------------"); } } | cs |
'프로그래머스 > lv0' 카테고리의 다른 글
| 피자 나눠 먹기 (1) (0) | 2022.12.05 |
|---|---|
| 피자 나눠 먹기 (2) (0) | 2022.12.05 |
| 배열의 평균값 (0) | 2022.12.05 |
| 나이출력 (0) | 2022.12.05 |
| 각도기 (0) | 2022.12.05 |