-
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
[장희직] Java vs C++, 1,2,3 더하기 4, 도어맨, 배열 복원하기, 후위 표기식2 #45
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,26 @@ | ||
package heejik.`9week` | ||
|
||
// 답보풀: https://ku-hug.tistory.com/m/209 | ||
|
||
class `1, 2, 3 더하기 4` { | ||
|
||
fun solve() { | ||
|
||
val cnt = MutableList(10001) { 1 } | ||
|
||
for (i in 2..10000) { | ||
cnt[i] += cnt[i-2] | ||
} | ||
|
||
for (i in 3..10000) { | ||
cnt[i] += cnt[i-3] | ||
} | ||
repeat(readln().toInt()) { | ||
println(cnt[readln().toInt()]) | ||
} | ||
} | ||
} | ||
|
||
fun main() { | ||
`1, 2, 3 더하기 4`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package heejik.`9week` | ||
|
||
class `Java vs C++` { | ||
|
||
data class JAVA(val variable: 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. data 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. 데이터 클래스로 포멧팅까지 하신 것 좋아요!! |
||
var cpp = "" | ||
fun toCPP(): 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. data class로 만들고 변환 함수 만드신 게 멋졌습니다! |
||
variable.forEach { c -> | ||
if (c.isUpperCase()) { | ||
cpp += '_' | ||
cpp += c.lowercaseChar() | ||
} else { | ||
cpp += c | ||
} | ||
} | ||
return cpp | ||
} | ||
} | ||
|
||
data class CPP(val variable: String) { | ||
var java = "" | ||
fun toJava(): String { | ||
var isUpper = false | ||
variable.forEach { c -> | ||
if (c == '_') { | ||
isUpper = true | ||
} else if (isUpper) { | ||
java += c.uppercaseChar() | ||
isUpper = false | ||
} else { | ||
java += c | ||
} | ||
} | ||
return java | ||
} | ||
} | ||
|
||
fun solve() { | ||
readln().run { | ||
if (this.first().isLetter().not() || this.first().isLowerCase().not() || this.last() == '_' || this.contains("__")) { | ||
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. isLetter 잘 배워갑니다!! 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. isLetter 시리즈 유용해보이네요! |
||
println("Error!") | ||
} else if (this.contains('_') && this.none { it.isUpperCase() }) { // CPP asd_asd | ||
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. none 고차함수 배우고 갑니다! |
||
println(CPP(this).toJava()) | ||
} else if (this.contains('_').not()){ // JAVA | ||
println(JAVA(this).toCPP()) | ||
} else { | ||
println("Error!") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
`Java vs C++`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package heejik.`9week` | ||
|
||
class 도어맨 { | ||
|
||
|
||
fun solve() { | ||
|
||
val x = readln().toInt() | ||
var answer = 0 | ||
val order = readln() | ||
var wCount = 0 | ||
var mCount = 0 | ||
var isChanged = false | ||
|
||
kotlin.run { | ||
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. 그냥 run말고 kotlin.run도 있다는 것을 배웠습니다 |
||
order.forEachIndexed { index, _c -> | ||
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. _c로 받은 다음에 var c = _c 하는 게 아이디어 좋다고 생각했습니다! |
||
var c = _c | ||
if (isChanged) { | ||
isChanged = false | ||
c = c.change() | ||
} | ||
if (c == 'W') { | ||
if (wCount - mCount == x) { | ||
if (index == order.length - 1 || order[index + 1] == 'W') return@run | ||
isChanged = true | ||
mCount++ | ||
} else wCount++ | ||
} else { | ||
if (mCount - wCount == x) { | ||
if (index == order.length - 1 || order[index + 1] == 'M') return@run | ||
isChanged = true | ||
wCount++ | ||
} else mCount++ | ||
} | ||
answer++ | ||
} | ||
} | ||
println(answer) | ||
} | ||
|
||
private fun Char.change() = if (this == 'W') 'M' else 'W' | ||
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() { | ||
|
||
도어맨().solve() | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package heejik.`9week` | ||
|
||
class `배열 복원하기` { | ||
|
||
fun solve() { | ||
|
||
val (h, w, x, y) = readln().split(' ').map { it.toInt() } | ||
|
||
val a = MutableList(h) { MutableList(w) { 0 } } | ||
val b = mutableListOf<MutableList<Int>>() | ||
|
||
repeat(h + x) { | ||
b.add(readln().split(' ').map { it.toInt() }.toMutableList()) | ||
} | ||
|
||
for (i in 0 until h) { | ||
for (j in 0 until w) { | ||
if (i >= x && j >= y) { | ||
a[i][j] = b[i][j] - a[i-x][j-y] | ||
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. 중복된 부분에 대한 처리를 한 번에 처리한 것이 깔끔하네요..!! |
||
} | ||
else { | ||
a[i][j] = b[i][j] | ||
} | ||
} | ||
} | ||
a.forEach { row -> | ||
row.forEach { value -> | ||
print("$value ") | ||
} | ||
println() | ||
} | ||
} | ||
} | ||
|
||
|
||
fun main() { | ||
`배열 복원하기`().solve() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package heejik.`9week` | ||
|
||
class `후위 표기식2` { | ||
|
||
val operands = mutableListOf<Double>() | ||
|
||
fun solve() { | ||
val n = readln().toInt() | ||
var postfix = readln().chunked(1).toMutableList() | ||
|
||
repeat(n) { cnt -> | ||
val num = readln() | ||
postfix = postfix.map { | ||
if (it.contains('A' + cnt)) num | ||
else it | ||
}.toMutableList() | ||
Comment on lines
+13
to
+16
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. map으로 입력 받으면서 바로 대입한 게 멋졌습니다! |
||
} | ||
|
||
postfix.forEach { | ||
if (it.toIntOrNull() != null) { | ||
operands.add(it.toDouble()) | ||
} else { | ||
val a = operands.removeLast() | ||
val b = operands.removeLast() | ||
when (it.first()) { | ||
'*' -> operands.add(b * a) | ||
'+' -> operands.add(b + a) | ||
'/' -> operands.add(b / a) | ||
'-' -> operands.add(b - a) | ||
} | ||
} | ||
} | ||
println(String.format("%.2f", operands.first())) | ||
} | ||
} | ||
|
||
fun main() { | ||
`후위 표기식2`().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.
좋은 자료 공유 감사합니다..!!