출처 : https://school.programmers.co.kr/learn/courses/30/lessons/132267
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int solution(int a, int b, int n) {
int answer = 0;
int cnt=0;
int bottle=n;
while(bottle>=a){
cnt++;
n=n-a;
if(n<a){
bottle=bottle-a*cnt+cnt*b;
answer+=cnt*b;
n=bottle;
cnt=0;
}
}
return answer;
}
}
단순 수학적 계산만 실수없이 한다면 쉽게 풀 수 있을 것 입니다.
'알고리즘 > Lv1. 프로그래머스' 카테고리의 다른 글
개인정보 수집 유효기간 (0) | 2023.07.13 |
---|---|
2016년 (0) | 2023.07.11 |
가장 가까운 같은 글자 (0) | 2023.07.11 |
푸드 파이트 대회 (0) | 2023.07.11 |
두 개 뽑아서 더하기 (0) | 2023.07.11 |