프로그래머스

[프로그래머스] 개미 군단

소금_msg 2022. 11. 29. 17:22
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(hp<gAnt&&hp>bAnt||hp==bAnt){
                cnt2 = hp/bAnt;
                hp = hp-(cnt2*bAnt);
            }
            
            else{
                hp = hp-sAnt;
                cnt3++;
                
            }
               
        }
   
        answer = cnt+cnt2+cnt3;
        return answer;
    }
}