Kotlin/Kotlin 알고리즘

백준 25704번 출석 이벤트 Kotlin 구현해보기

kimc 2022. 10. 3. 21:10

```

백준 25704번 출석 이벤트 Kotlin 구현해보기

```

Kimc Kotlin Study

이번 글을 통해 배워갈 내용

  1. 백준 25704번 출석 이벤트 Kotlin 구현해보기

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

 

25704번: 출석 이벤트

쇼핑몰에서 30일간 출석 이벤트를 진행한다. 쇼핑몰의 사이트를 방문하면 1일 1회 출석 도장을 받을 수 있고, 출석 도장을 여러 개 모아서 할인 쿠폰으로 교환할 수 있다. 출석 도장의 개수에 따

www.acmicpc.net

 

백준 25704번 출석 이벤트는

 

출석도장에 따라서 다른 할인율을 받을 경우

최고의 할인률을 적용해서

가장 적은 지불금액을 구해주면 되는 문제입니다.


30분 정도 위에 링크를 방문하셔서 풀어보시고

안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.


출석도장에 따른 모든 할인율을 구한 다음

리스트 스트림으로 최솟값을 구해서

출력했습니다.

 

import kotlin.math.max

fun main(args: Array<String>) {
    // 입력
    val stampCnt = (readln()).toInt()
    val productPrice = (readln()).toInt()
    // 출력
    print(findDiscountedPrice(stampCnt, productPrice))
}

fun findDiscountedPrice(stampCnt: Int, productPrice: Int): Int? {
    val discounts = ArrayList<Int>()
    discounts.add(productPrice)

    if (stampCnt >= 5) {
        discounts.add(max(productPrice - 500, 0))
    }
    if (stampCnt >= 10) {
        discounts.add((productPrice * 0.9).toInt())
    }
    if (stampCnt >= 15) {
        discounts.add(max(productPrice - 2000, 0))
    }
    if (stampCnt >= 20) {
        discounts.add((productPrice * 0.75).toInt())
    }

    return discounts.minOrNull()
}

// https://codemasterkimc.tistory.com/

 

 

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90