-
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
[장희직] - 민겸 수, 이모티콘 할인 행사 #209
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e2c1679
solve K진수에서 소수 개수 구하기
jhg3410 2fb78b5
solve 거리두기 확인하기
jhg3410 0ef8768
solve 거리두기 확인하기2
jhg3410 49ae8ea
solve 민겸 수
jhg3410 2180d82
solve 양궁대회
jhg3410 e98f338
solve 이모티콘 할인행사
jhg3410 7cf4522
solve 주차 요금
jhg3410 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,51 @@ | ||
package heejik.`51week` | ||
|
||
import java.math.BigInteger | ||
import kotlin.math.sqrt | ||
|
||
class `k진수에서 소수 개수 구하기` { | ||
fun solution(n: Int, k: Int): Int { | ||
var answerCount = 0 | ||
|
||
n.changeToKNumber(k).split('0').forEach { | ||
it.toLongOrNull()?.let { | ||
if (it.isPrimeNumber()) answerCount++ | ||
} | ||
} | ||
|
||
return answerCount | ||
} | ||
|
||
|
||
private fun Int.changeToKNumber(k: Int): String { | ||
var tmp = this | ||
val sb = StringBuilder() | ||
|
||
while (tmp >= k) { | ||
sb.insert(0, tmp % k) | ||
tmp /= k | ||
} | ||
sb.insert(0, tmp) | ||
return sb.toString() | ||
} | ||
|
||
private fun Long.isPrimeNumber(): Boolean { | ||
|
||
|
||
if (this == 1L) return false | ||
if (this == 2L) return true | ||
if (this % 2 == 0.toLong()) return false | ||
|
||
for (i in 3..sqrt(this.toDouble()).toInt()) { | ||
if (this % i == 0.toLong()) return false | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
fun main() { | ||
`k진수에서 소수 개수 구하기`().solution( | ||
n = 437674, k = 3 | ||
) | ||
} |
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,79 @@ | ||
package heejik.`51week` | ||
|
||
// P -> 응시자 | O -> 빈테이블 | X -> 파티션 | ||
|
||
class `거리두기 확인하기` { | ||
data class Pos( | ||
val x: Int, | ||
val y: Int, | ||
) | ||
|
||
// 위, 오른, 아래, 왼, 오.위, 오.아래, 왼.위, 왼.아래 | ||
private val checkDistance = listOf( | ||
Pos(-2, 0), | ||
Pos(0, 2), | ||
Pos(2, 0), | ||
Pos(0, -2), | ||
// ------------- | ||
Pos(-1, 1), | ||
Pos(1, 1), | ||
Pos(-1, -1), | ||
Pos(1, -1) | ||
) | ||
private val checkPos = listOf( | ||
listOf(Pos(-1, 0)), | ||
listOf(Pos(0, 1)), | ||
listOf(Pos(1, 0)), | ||
listOf(Pos(0, -1)), | ||
// ------------------ | ||
listOf(Pos(-1, 0), Pos(0, 1)), | ||
listOf(Pos(1, 0), Pos(0, 1)), | ||
listOf(Pos(-1, 0), Pos(0, -1)), | ||
listOf(Pos(1, 0), Pos(0, -1)) | ||
) | ||
|
||
|
||
fun solution(places: Array<Array<String>>): IntArray { | ||
val answer: MutableList<Int> = MutableList(size = 5) { -1 } | ||
|
||
places.forEachIndexed { order, waitingRoom -> | ||
val isKeepDistance = checkKeepDistance(waitingRoom = waitingRoom.toList()) | ||
answer[order] = if (isKeepDistance) 1 else 0 | ||
} | ||
|
||
return answer.toIntArray() | ||
} | ||
|
||
|
||
private fun checkKeepDistance(waitingRoom: List<String>): Boolean { | ||
for ((x, row) in waitingRoom.withIndex()) { | ||
for ((y, element) in row.withIndex()) { | ||
if (element == 'P') { | ||
|
||
// distance == 2 | ||
repeat(checkDistance.size) { | ||
val nx = x + checkDistance[it].x | ||
val ny = y + checkDistance[it].y | ||
|
||
if (nx in 0 until 5 && ny in 0 until 5 && waitingRoom[nx][ny] == 'P') { | ||
checkPos[it].forEach { check -> | ||
val checkX = x + check.x | ||
val checkY = y + check.y | ||
if (waitingRoom[checkX][checkY] == 'O') return true | ||
} | ||
} | ||
} | ||
|
||
// distance == 1 | ||
listOf(Pos(1, 0), Pos(-1, 0), Pos(0, 1), Pos(0, -1)).forEach { | ||
val nx = x + it.x | ||
val ny = y + it.y | ||
|
||
if (nx in 0 until 5 && ny in 0 until 5 && waitingRoom[nx][ny] == 'P') return true | ||
} | ||
} | ||
} | ||
} | ||
return false | ||
} | ||
} |
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,54 @@ | ||
package heejik.`51week` | ||
|
||
class `거리두기 확인하기2` { | ||
|
||
fun solution(places: Array<Array<String>>): IntArray { | ||
val answer = mutableListOf<Int>() | ||
|
||
places.forEach { place -> | ||
repeat(5) { x -> | ||
repeat(5) { y -> | ||
if (place[x][y] == 'P') { | ||
if (check(place, 0, x, y, 0).not()) { | ||
answer.add(0) | ||
return@forEach | ||
} | ||
} | ||
} | ||
} | ||
answer.add(1) | ||
} | ||
|
||
return answer.toIntArray() | ||
} | ||
|
||
|
||
fun check(place: Array<String>, depth: Int, x: Int, y: Int, skip: Int): Boolean { | ||
var result = true | ||
|
||
if (x < place.lastIndex) { | ||
when (place[x + 1][y]) { | ||
'P' -> return false | ||
'O' -> if (depth == 0) result = check(place, 1, x + 1, y, 0) | ||
} | ||
} | ||
|
||
if (result && y - 1 >= 0 && skip != -1) { | ||
when (place[x][y - 1]) { | ||
'P' -> return false | ||
'O' -> if (depth == 0) result = check(place, 1, x, y - 1, 1) | ||
} | ||
} | ||
|
||
|
||
if (result && y < place.lastIndex && skip != 1) { | ||
when (place[x][y + 1]) { | ||
'P' -> return false | ||
'O' -> if (depth == 0) result = check(place, 1, x, y + 1, -1) | ||
} | ||
} | ||
|
||
|
||
return result | ||
} | ||
} |
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,62 @@ | ||
package heejik.`51week` | ||
|
||
class `민겸 수` { | ||
|
||
fun solve() { | ||
readln().run { | ||
getMaxDecimal().also { println(it) } | ||
getMinDecimal().also { println(it) } | ||
} | ||
} | ||
|
||
private fun String.getMaxDecimal(): String { | ||
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. 확장함수가 예쁘네용 |
||
var mStackCount = 0 | ||
val decimal = StringBuilder() | ||
|
||
this.forEach { | ||
if (it == 'M') mStackCount += 1 | ||
if (it == 'K') { | ||
decimal.append(5) | ||
repeat(mStackCount) { | ||
decimal.append(0) | ||
} | ||
mStackCount = 0 | ||
} | ||
} | ||
repeat(mStackCount) { | ||
decimal.append(1) | ||
} | ||
return decimal.toString() | ||
} | ||
|
||
private fun String.getMinDecimal(): String { | ||
var mStackCount = 0 | ||
val decimal = StringBuilder() | ||
|
||
this.forEach { | ||
if (it == 'M') mStackCount += 1 | ||
if (it == 'K') { | ||
if (mStackCount > 0) { | ||
decimal.append(1) | ||
} | ||
repeat(mStackCount - 1) { | ||
decimal.append(0) | ||
} | ||
decimal.append(5) | ||
mStackCount = 0 | ||
} | ||
} | ||
|
||
if (mStackCount != 0) { | ||
decimal.append(1) | ||
repeat(mStackCount - 1) { | ||
decimal.append(0) | ||
} | ||
} | ||
return decimal.toString() | ||
} | ||
} | ||
|
||
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,81 @@ | ||
package heejik.`51week` | ||
|
||
class 양궁대회 { | ||
var maxDifference = 0 | ||
|
||
// 점수: 과녁 갯수 | ||
private val answerList = MutableList(11) { 0 } | ||
var answer: Map<Int, Int> = mapOf() | ||
fun solution(n: Int, info: IntArray): IntArray { | ||
shot(n, mutableMapOf(), 0, info) | ||
|
||
answer.forEach { (key, value) -> | ||
answerList[10 - key] = value | ||
} | ||
return answerList.toIntArray().run { | ||
if (this.all { it == 0 }) intArrayOf(-1) else this | ||
} | ||
} | ||
|
||
private fun shot(remainArrow: Int, scoreWithCount: MutableMap<Int, Int>, idx: Int, info: IntArray) { | ||
if (idx == 10 && remainArrow > 0) { | ||
scoreWithCount[0] = remainArrow | ||
shot(remainArrow = 0, scoreWithCount = scoreWithCount, idx = -1, info = info) | ||
scoreWithCount.remove(0) | ||
} | ||
if (remainArrow == 0) { | ||
var apeachScore = 0 | ||
info.withIndex().filter { it.value != 0 }.forEach { | ||
if (it.index !in scoreWithCount.keys.map { key -> 10 - key }) { | ||
apeachScore += (10 - it.index) | ||
} | ||
} | ||
val difference = scoreWithCount.keys.sum() - apeachScore | ||
if (difference <= 0) return | ||
if (difference > maxDifference) { | ||
maxDifference = difference | ||
answer = scoreWithCount.toMap() | ||
} | ||
else if (difference == maxDifference) { | ||
for (score in 0..10) { | ||
val isAnswerContain = answer.containsKey(score) | ||
val isScoreWithCountContain = scoreWithCount.containsKey(score) | ||
if (isAnswerContain && isScoreWithCountContain) { | ||
if (scoreWithCount[score]!! > answer[score]!!) { | ||
maxDifference = difference | ||
answer = scoreWithCount.toMap() | ||
} | ||
} else if (isAnswerContain) { | ||
break | ||
} else if (isScoreWithCountContain) { | ||
maxDifference = difference | ||
answer = scoreWithCount.toMap() | ||
} | ||
} | ||
} | ||
return | ||
} | ||
for (i in idx..9) { | ||
if (remainArrow - (info[i] + 1) >= 0) { | ||
scoreWithCount[10 - i] = info[i] + 1 | ||
shot( | ||
remainArrow = remainArrow - (info[i] + 1), | ||
scoreWithCount = scoreWithCount, | ||
idx = i + 1, | ||
info = info | ||
) | ||
scoreWithCount.remove(10 - i) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
양궁대회().solution( | ||
n = 10, | ||
info = intArrayOf(0,0,0,0,0,0,0,0,3,4,3) | ||
).also { | ||
println(it.contentToString()) | ||
} | ||
} |
Oops, something went wrong.
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.
확장함수 오랜만에 보네요,,,