Skip to content

Latest commit

 

History

History
87 lines (69 loc) · 1.75 KB

3회차_2022.04.26_부족한 금액 계산하기.md

File metadata and controls

87 lines (69 loc) · 1.75 KB

image

강지웅

import Foundation

func solution(_ price:Int, _ money:Int, _ count:Int) -> Int64{
    var cost = 0
    
    for i in 1...count {
        cost += price * i
    }
    
    return money - cost >= 0 ? 0 : Int64(cost - money)
}

서예진

class Solution {
    public long solution(int price, int money, int count) {
        long answer = -1;
        long sum = 0;
        
        for(int i = 1; i <= count; i++){
            sum += price * i;
        }
        
        if(sum < money){
            return 0;
        }
        answer = sum - money;
        
        return answer;
    }
}

오나연

class Solution {
    public long solution(int price, int money, int count) {
        long answer = 0;
        for(int i=1; i<=count; i++) answer+=price*i;
        
        return (answer>money)? (answer-money) : 0;
    }
}

이주형

class Solution {
    public long solution(int price, int money, int count) {
        long totalPrice = 0;
        
        for (int i = 1; i <= count; i++) {
            totalPrice += (price * i);
        }
        
        return (totalPrice > money) ? totalPrice - money : 0;
    }
}

정윤영

class Solution {
    public long solution(int price, int money, int count) {
        long answer = 0;
        
        for(int i=1; i<=count; i++){
            answer += price*i;
        }

        return answer-money>0?answer-money:0;
    }
}