728x90
반응형
SMALL
#include <string>
#include <vector>
using namespace std;
int solution(int hp) {
// 장군개미 5
// 병정개미 3
// 일개미 1
vector<int> hps = {5,3,1};
int jang = hp/hps[0];
int byeung = (hp-jang*hps[0])/hps[1];
int il = (hp-jang*hps[0]-byeung*hps[1])/hps[2];;
return jang + byeung + il;
}
* 간단하게 다음과 같이 변경 가능
#include <string>
#include <vector>
using namespace std;
int solution(int hp) {
// 장군개미 5
// 병정개미 3
// 일개미 1
int answer = 0;
for(int h=5; h>0; h-=2){
answer += hp/h;
hp %= h;
}
return answer;
}
728x90
반응형
LIST
'C++' 카테고리의 다른 글
[프로그래머스] 주사위의 개수 (0) | 2025.09.05 |
---|---|
[프로그래머스] 가위 바위 보 (0) | 2025.09.05 |
[프로그래머스] 직각삼각형 출력하기 (0) | 2025.09.04 |
[프로그래머스] 옷가게 할인 받기 (0) | 2025.09.04 |
[프로그래머스] 모음 제거 (0) | 2025.09.04 |
댓글