Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] MVP 다이아몬드 (Easy) #206

Closed
hwangJi-dev opened this issue Apr 20, 2023 · 0 comments
Closed

[Algorithm] MVP 다이아몬드 (Easy) #206

hwangJi-dev opened this issue Apr 20, 2023 · 0 comments
Assignees

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Apr 20, 2023

💬 문제

https://www.acmicpc.net/problem/20413


💬 Idea

  • 이전 달의 과금액을 저장해둔다.
  • 현재 달의 등급 최고 과금액에서 이전 달 최고 과금액을 빼서 현재 달의 과금액을 산정한다.
  • 이달의 MVP 산정 등급이 D일 경우에는 최고 금액인 다이아몬드 등급 기준액까지만 과금할 수 있으므로 최대 D 기준액만큼 과금한 것으로 판단한다.

💬 풀이

import Foundation
 
func solution20413() {
    let _ = Int(readLine()!)!
    let money = readLine()!.components(separatedBy: .whitespaces).map({ Int($0)! })
    let tier = Array(readLine()!).map({ String($0) })
    var moneyDict: [String: Int] = ["B": 0, "S": 0, "G": 0, "P": 0, "D": 0]
    
    moneyDict["B"] = money[0] - 1
    moneyDict["S"] = money[1] - 1
    moneyDict["G"] = money[2] - 1
    moneyDict["P"] = money[3] - 1
    moneyDict["D"] = money[3]
    
    var sumMoney = 0
    var lastMoney = 0
    
    for i in tier {
        let tierStandard = moneyDict[i]!
        var currentMoney = tierStandard - lastMoney
        if i == "D" {
            currentMoney = moneyDict[i]!
        }
        lastMoney = currentMoney
        sumMoney += currentMoney
    }
    
    print(sumMoney)
}

소요시간 : 36분

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant