-
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
[장희직] 기적의 매매법, 수 이어 쓰기 1, 등수 구하기, DNA #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package heejik.`13week` | ||
|
||
import java.lang.Integer.max | ||
|
||
|
||
class DNA { | ||
|
||
fun solve() { | ||
|
||
var answerDna = "" | ||
var answerCnt = 0 | ||
|
||
val (n, m) = readln().split(' ').map { it.toInt() } | ||
|
||
val dnaList = mutableListOf<String>() | ||
|
||
repeat(n) { dnaList.add(readln()) } | ||
|
||
repeat(m) { | ||
var dnaByIdx = "" | ||
dnaList.forEach { dna -> dnaByIdx += dna[it] } | ||
|
||
var maxCnt = 0 | ||
"ACGT".forEach { c -> maxCnt = max(maxCnt, dnaByIdx.count { c == it }) } | ||
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. ACGT 문자열로 만들어 푸신게 인상적이었습니다! |
||
|
||
answerDna += dnaByIdx.filter { c -> maxCnt == dnaByIdx.count { c == it } }.min() | ||
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. 문자열이랑 고차함수를 엄청 잘 다루시네요! |
||
answerCnt += dnaByIdx.count { it != answerDna.last() } | ||
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. 여기가 혹시 n - maxCnt도 되지 않을까요! |
||
} | ||
|
||
println(answerDna) | ||
println(answerCnt) | ||
} | ||
} | ||
|
||
fun main() { | ||
|
||
DNA().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package heejik.`13week` | ||
|
||
class `등수 구하기` { | ||
|
||
fun solve() { | ||
val (n, score, p) = readln().split(' ').map { it.toInt() } | ||
|
||
if (n == 0) { | ||
println(1) | ||
return | ||
} | ||
val scores = readln().split(' ').map { it.toInt() }.toMutableList() | ||
|
||
scores.sort() | ||
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. 거꾸로 정렬하신 것도 신기했는데 count로 세면 아예 정렬할 필요가 없는 게 대박이네유.. |
||
|
||
if (scores.count { it >= score } >= p) { | ||
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. count 활용을 잘하시네요 👍 |
||
println(-1) | ||
} else { | ||
println(scores.count { it > score } + 1) | ||
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. count를 단순히 개수를 셀 때만 이용했는데... 역시 똑똑하십니다. |
||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`등수 구하기`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package heejik.`13week` | ||
|
||
class `수 이어 쓰기 1` { | ||
|
||
fun solve() { | ||
val n = readln().toInt() | ||
var answer = 0 | ||
|
||
repeat(n) { | ||
answer += getDigit(it+1) | ||
} | ||
|
||
println(answer) | ||
} | ||
|
||
private fun getDigit(_num : Int): Int { | ||
var num = _num | ||
var cnt = 0 | ||
while (num != 0) { | ||
num /= 10 | ||
cnt ++ | ||
} | ||
return cnt | ||
} | ||
Comment on lines
+16
to
+24
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. 엄청 깔끔하게 푸셔서 놀랐어요! |
||
} | ||
|
||
fun main() { | ||
`수 이어 쓰기 1`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package heejik.`13week` | ||
|
||
class 시계 { | ||
|
||
val nums = listOf( | ||
"####.##.##.####", // 0 | ||
"..#..#..#..#..#", // 1 | ||
"###..#####..###", // 2 | ||
"###..####..####", // 3 | ||
"#.##.####..#..#", // 4 | ||
"####..###..####", // 5 | ||
"####..####.####", // 6 | ||
"###..#..#..#..#", // 7 | ||
"####.#####.####", // 8 | ||
"####.####..####" // 9 | ||
) | ||
|
||
fun solve() { | ||
val watch = mutableListOf<List<String>>() | ||
repeat(5) { | ||
watch.add(readln().split(' ')) | ||
} | ||
|
||
val hourFirst = find(watch.joinToString(separator = "") { it[0] }) | ||
val hourSecond = find(watch.joinToString(separator = "") { it[1] }) | ||
val minuteFirst = find(watch.joinToString(separator = "") { it[2] }) | ||
val minuteSecond = find(watch.joinToString(separator = "") { it[3] }) | ||
|
||
println("$hourFirst$hourSecond:$minuteFirst$minuteSecond") | ||
} | ||
|
||
fun find(diode: String): Int { | ||
nums.forEach { num -> | ||
num.forEachIndexed { index, c -> | ||
if (c == '.' && diode[index] == '#') return@forEach | ||
} | ||
return nums.indexOf(num) | ||
} | ||
return -1 | ||
} | ||
} | ||
|
||
fun main() { | ||
시계().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package heejik.`13week` | ||
|
||
class 크로스워드 { | ||
|
||
fun solve() { | ||
|
||
val (r, c) = readln().split(' ').map { it.toInt() } | ||
|
||
val crossWord = mutableListOf<String>() | ||
val words = mutableListOf<String>() | ||
|
||
|
||
repeat(r) { | ||
val row = readln() | ||
crossWord.add(row) | ||
row.split('#').forEach { | ||
if (it.length > 1) words.add(it) | ||
} | ||
} | ||
|
||
repeat(c) { n -> | ||
crossWord.joinToString(separator = "") { it[n].toString() }.split('#').forEach { | ||
if (it.length > 1) words.add(it) | ||
} | ||
} | ||
|
||
println(words.minOrNull()) | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
크로스워드().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package heejik.`13week` | ||
|
||
class `🐜 기적의 매매법 🐜` { | ||
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. 개미까지 복사하신게 인상깊네요 :) |
||
|
||
fun solve() { | ||
val money = readln().toInt() | ||
val stocks = readln().split(' ').map { it.toInt() } | ||
|
||
val bnf = bnf(money, stocks) | ||
val timing = timing(money, stocks) | ||
Comment on lines
+9
to
+10
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. 함수 만들어 사용하신게 깔끔하니 좋네요 👍 |
||
|
||
println( | ||
if (bnf > timing) "BNP" | ||
else if (timing > bnf) "TIMING" | ||
else "SAMESAME" | ||
) | ||
} | ||
|
||
private fun bnf(_money: Int, stocks: List<Int>): Int { | ||
var money = _money | ||
var stock = 0 | ||
|
||
stocks.forEach { | ||
val cnt = money / it | ||
money -= it * (cnt) | ||
stock += cnt | ||
} | ||
|
||
return money + (stock * stocks.last()) | ||
} | ||
|
||
private fun timing(_money: Int, stocks: List<Int>): Int { | ||
var money = _money | ||
var stock = 0 | ||
|
||
var upCnt = 0 | ||
var downCnt = 0 | ||
var preStock = stocks.first() | ||
|
||
stocks.drop(0).forEach { | ||
if (it > preStock) { | ||
upCnt++ | ||
downCnt = 0 | ||
} else if (it < preStock) { | ||
downCnt++ | ||
upCnt = 0 | ||
} else { | ||
upCnt = 0 | ||
downCnt = 0 | ||
} | ||
|
||
if (upCnt >= 3) { | ||
money += stock * it | ||
stock = 0 | ||
} | ||
if (downCnt >= 3) { | ||
val cnt = money / it | ||
money -= it * (cnt) | ||
stock += cnt | ||
} | ||
|
||
preStock = it | ||
} | ||
|
||
return money + (stock * stocks.last()) | ||
} | ||
} | ||
|
||
fun main() { | ||
`🐜 기적의 매매법 🐜`().solve() | ||
} |
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.
문자열 써서 인덱스로 이용하는 거 좋아보이네요...👍