Skip to content

Commit

Permalink
Feat: 할인 행사 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach committed Nov 12, 2023
1 parent 5b0efb2 commit 2e0432e
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/main/kotlin/hyunsoo/49week/할인 행사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package hyunsoo.`49week`

/**
*
* <문제>
* [할인 행사](https://school.programmers.co.kr/learn/courses/30/lessons/131127)
*
* - 아이디어
*
* - 트러블 슈팅
*
*/
class `전현수_할인_행사` {

fun solution(want: Array<String>, number: IntArray, discount: Array<String>): Int {

var answer = 0

for (i in 0 .. discount.size - 10) {

val wishList = mutableMapOf<String, Int>()

want.forEachIndexed { index, item ->
wishList[item] = number[index]
}

repeat(10) {
val index = i + it
wishList[discount[index]]?.let { pre ->
wishList[discount[index]] = pre - 1
}
}
if (wishList.values.all { it <= 0 }) answer += 1
}

return answer
}
}

fun main() {
전현수_할인_행사().solution(
arrayOf("banana", "apple", "rice", "pork", "pot"),
intArrayOf(3, 2, 2, 2, 1),
arrayOf(
"chicken",
"apple",
"apple",
"banana",
"rice",
"apple",
"pork",
"banana",
"pork",
"rice",
"pot",
"banana",
"apple",
"banana"
)
).apply {
println(this)
}
}

0 comments on commit 2e0432e

Please sign in to comment.