개미 군단1 [프로그래머스] 개미 군단 class Solution { public int solution(int hp) { int answer = 0; int gAnt = 5; int bAnt = 3; int sAnt = 1; int cnt = 0; int cnt2 = 0; int cnt3 = 0; while(hp!=0){ if(hp>gAnt||hp==gAnt){ cnt = hp/gAnt; hp = hp-(cnt*gAnt); } else if(hpbAnt||hp==bAnt){ cnt2 = hp/bAnt; hp = hp-(cnt2*bAnt); } else{ hp = hp-sAnt; cnt3++; } } answer = cnt+cnt2+cnt3; return answer; } } 2022. 11. 29. 이전 1 다음