N

(프로그래머스 c++) 콜라 문제 본문

프로그래머스 알고리즘/0 & 1단계

(프로그래머스 c++) 콜라 문제

naeunchan 2025. 10. 9. 16:27
728x90
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/132267

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

문제만 잘 이해하면 풀 수 있는 문제.

설명은 굳이 없어도 될 것 같다.

int solution(int a, int b, int n) {
    int answer = 0;
    
    while (n >= a) {
        answer += ((n / a) * b);
        n = ((n / a) * b) + (n % a);
    }
    
    return answer;
}
728x90
반응형