풀이
class Solution {
public int solution(int a, int b, int n) {
int answer = 0;
while(n>=a){
int tmp=n/a;
int tmp2=tmp*b;
n=n-tmp*a+tmp*b; //현재 보유한 콜라 병 수
answer+=tmp2;
}
return answer;
}
}
간단한 문제다.
다만 주의할 점은 역시나 콜라를 몇 병 당 몇 병으로 다시 페이백해주는지에 대한 처리를 해줘야 된다는 점이다.
그것만 제외한다면 나머지는 while문에서 돌아가는 간단한 문제이다.