static int howManyGames(int p, int d, int m, int s) {
        // Return the number of games you can buy
        int salePrice = p;//세일 시작가격
        int count = 0;//구매한 게임수
        while(s >= salePrice ){
            count++;//게임개수증가
            s -= salePrice;//남은돈
            //System.out.println("Buy salePrice="+salePrice+", count="+count+", s="+s);
            if(salePrice > m){
                salePrice -= d;//세일 적용
            }
            if(salePrice < m){//최저세일가 보장
                salePrice = m;
            }           
        }
        return count;
    }

'개발 > CodingTest' 카테고리의 다른 글

Hackerrank - Utopian Tree  (0) 2020.06.25
Hacckerrank - The Hurdle Race  (0) 2020.06.25
Hackerrank - Prime Checker  (0) 2020.06.05
프로그래머스 - 기능개발  (0) 2020.06.03
프로그래머스 - 탑  (0) 2020.06.03
Posted by Lumasca
,