[algorithm]다단계 칫솔 판매

코드깎는 노인·2021년 10월 24일
0
post-custom-banner
function solution(enroll, referral, seller, amount) {
    var answer = [];
    let refer={}
    let profit={}
    let current
    for(let index in enroll){
            refer[enroll[index]]=referral[index]
            profit[enroll[index]]=0
    }
    for(let sellerIndex in seller){
         profit[seller[sellerIndex]]+=amount[sellerIndex]*100
         let currPerson=seller[sellerIndex]
         let currProfit=amount[sellerIndex]*100
        while(refer[currPerson]){
            profit[refer[currPerson]]+=Math.floor(currProfit*0.1)
            profit[currPerson]-=Math.floor(currProfit*0.1)
            currPerson=refer[currPerson]
            currProfit=Math.floor(currProfit*0.1)
            if(currProfit<=0){
                break;
            }
        }
    }
    for(let person of enroll){
        answer.push(profit[person])
    }
    return answer;
}
profile
내가 볼려고 만든 블로그
post-custom-banner

0개의 댓글