https://school.programmers.co.kr/learn/courses/30/lessons/132267
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 의사 코드
while로 새로운 answer값의 변화가 없을 때 정지
교환해서 받은 병 수를 answer에 저장
새로운 병 수 = 이전 병 수 - 교환하는데 사용한 병 수 + 교환해서 받은 병 수
반복
2. 제출 코드
#include <string>
#include <vector>
using namespace std;
int solution(int a, int b, int n) {
int answer = 0;
while(true)
{
int tempAnswer = answer;
int nBottle = (n/a) * b;
answer += nBottle;
n = n - (n/a) * a + nBottle;
if(tempAnswer == answer)
{
break;
}
}
return answer;
}
3. Trouble Shooting
반응형
'AlgorithmCodekata' 카테고리의 다른 글
| [AlgorithmCodeKata] 2026-03-25 | 카드 뭉치 (0) | 2026.03.25 |
|---|---|
| [AlgorithmCodeKata] 2026-03-23 | 명예의 전당 (1) (0) | 2026.03.23 |
| [AlgorithmCodeKata] 2026-03-18 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.18 |
| [AlgorithmCodeKata] 2026-03-12 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.12 |
| [AlgorithmCodeKata] 2026-03-11 | 숫자 문자열과 영단어 (0) | 2026.03.11 |