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

[이지민] - 민겸 수, 이모티콘 할인 행사 #208

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/main/kotlin/jimin/51week/민겸 수.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package jimin.`51week`

import kotlin.math.*

class `민겸 수` {
fun solve() {
val maxResult = StringBuilder()
val minResult = StringBuilder()

val mgValue = readln()

var firstIdx = 0
for (i in mgValue.indices) {
if (mgValue[i] == 'K') {
changeToDecimal(firstIdx, i, mgValue, maxResult)
changeToDecimal(firstIdx, i - 1, mgValue, minResult)
minResult.append(5)
firstIdx = i + 1
}
}

for(i in firstIdx until mgValue.length) {
maxResult.append(1)
}
changeToDecimal(firstIdx, mgValue.length - 1, mgValue, minResult)

println(maxResult)
println(minResult)
}

private fun changeToDecimal(first: Int, last: Int, mgValue: String, maxResult: StringBuilder) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최대랑 최소랑 겹치는 부분을 따로 함수로 빼서 깔끔하네요!!

if(last < first) {
return
}

if (mgValue[last] == 'K') {
maxResult.append(5)
} else {
maxResult.append(1)
}
repeat(last - first) {
maxResult.append(0)
}
}
}

fun main() {
`민겸 수`().solve()
}
70 changes: 70 additions & 0 deletions src/main/kotlin/jimin/51week/이모티콘 할인 행사.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package jimin.`51week`

class Solution {

val discountCombi = mutableListOf<MutableList<Int>>()
val discountPrices = mutableListOf<MutableList<Int>>()
val discountType = mutableListOf(10, 20, 30 ,40)

fun solution(users: Array<IntArray>, emoticons: IntArray): IntArray {
var plusCount = 0
var maxi = 0

getCombination(0, emoticons.size, mutableListOf<Int>())
makeDiscountPrices(emoticons)
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수를 역할별로 나눠서 필요한 값들을 다 구하고 마지막에 답을 갱신하는 흐름이 좋았워요

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공감합니다!


for (i in 0 until discountCombi.size) {
var result = 0
var count = 0
for (user in users) {
var sumi = 0
for (j in 0 until discountCombi[i].size) {
if (user[0] <= discountType[discountCombi[i][j]]) {
sumi += discountPrices[j][discountCombi[i][j]]
}
}

if (sumi >= user[1]) {
count += 1
} else {
result += sumi
}
}

if (count > plusCount) {
plusCount = count
maxi = result
} else if (count == plusCount && result > maxi) {
maxi = result
}
}


return intArrayOf(plusCount, maxi)
}

fun getCombination(num: Int, end: Int, combis: MutableList<Int>) {
if (num == end) {
discountCombi.add(combis)
return
}

for (i in 0 until 4) {
combis.add(i)
getCombination(num + 1, end, combis.toMutableList())
combis.removeAt(combis.size - 1)
}

}

fun makeDiscountPrices(emoticons: IntArray) {
val prices = mutableListOf<Int>()
for(i in 0 until emoticons.size) {
for (j in 9 downTo 6) {
prices.add((emoticons[i] * j * 0.1).toInt())
}
discountPrices.add(prices.toMutableList())
prices.clear()
}
}
}