-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
if(last < first) { | ||
return | ||
} | ||
|
||
if (mgValue[last] == 'K') { | ||
maxResult.append(5) | ||
} else { | ||
maxResult.append(1) | ||
} | ||
repeat(last - first) { | ||
maxResult.append(0) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`민겸 수`().solve() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수를 역할별로 나눠서 필요한 값들을 다 구하고 마지막에 답을 갱신하는 흐름이 좋았워요 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
최대랑 최소랑 겹치는 부분을 따로 함수로 빼서 깔끔하네요!!