728x90
SMALL

using System;

public class Solution {
    public int solution(int hp) {
        int answer = 0;
        //장군개미 5
        //병정개미 3
        //일개미 1
        while(hp >= 5)
        {
            hp = hp-5;
            answer++;
        }
        
        while(hp >= 3)
        {
            hp = hp-3;
            answer++;
        }
            
        while(hp >= 1)
        {
            hp = hp-1;
            answer++;
        }
        
        return answer;
    }
}

 

/// 이러면 시간 개 오래 걸린다.

 

using System;

public class Solution {
    public int solution(int hp) {
        int answer = 0;

        int ant_5 = hp / 5;
        int ant_3 = (hp % 5) / 3  ;
        int ant_1 = (hp % 5) % 3 / 1 ;

        return ant_5 + ant_3 + ant_1;
    }
}

 

파이썬

 

def solution(hp):    
    return hp // 5 + (hp % 5 // 3) + ((hp % 5) % 3)

 

 

자바

 

 

class Solution {
    public int solution(int hp) {
        int answer = hp / 5;
        hp %= 5;

        answer += hp / 3;
        hp %= 3;

        answer += hp / 1;

        return answer;
    }
}
728x90

설정

트랙백

댓글