본문 바로가기
알고리즘 & 자료구조/프로그래머스

콜라 문제

by 신재권 2022. 11. 10.
package programmers;

public class 콜라문제 {

   public static int solution(int a, int b, int n) {
      int cola = 0;
      while (n >= a) {
         cola += (n / a) * b;
         n = (n / a) * b + (n % a);
      }

      return cola;
   }

   public static void main(String[] args) {
      System.out.println(solution(2, 1, 20));
      System.out.println(solution(3, 1, 20));
      System.out.println(solution(3,2,20));
   }
   
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

숫자 짝궁  (0) 2022.11.13
푸드 파이트 대회  (0) 2022.11.11
체육복  (0) 2022.11.09
다트 게임  (0) 2022.11.08
실패율  (0) 2022.11.06