-
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 #44
Conversation
wait.indexOfFirst { | ||
count += it | ||
abs(count) > d + 1 |
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.
indexOfFirst 신기하네요!! count가 계속 실행된다는 것을 병희님 덕분에 알게 되었습니다
}.let { ans -> when (ans) { | ||
-1 -> if (abs(count) == d + 1) println(wait.size - 1) else println(wait.size) | ||
else -> println(ans - 1) | ||
} } |
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.
로직이 넘 깔끔해서 감탄했습니다!! 차이에서 하나를 더 더한 걸 생각한게 놀라웠어요
val op: (Double, Double) -> Double = | ||
when (opC) { | ||
MUL -> { b, a -> a * b } | ||
DIV -> { b, a -> a / b } | ||
ADD -> { b, a -> a + b } | ||
SUB -> { b, a -> a - b } | ||
else -> { _, _ -> 0.0 } | ||
} | ||
st.addLast(op(n1, n2)) |
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.
람다함수 사용 👍
if (prev == UNDERSCORE) { | ||
if (cur.isLowerCase()) { | ||
sb.append(cur.uppercase()) | ||
} | ||
else error() | ||
} | ||
else if (cur.isUpperCase()) { | ||
sb.append("_${cur.lowercase()}") | ||
} |
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.
굳이 C++ 랑 JAVA 나누지 않고 이렇게 하는 게 더 좋네요!👍
matrixA[r][c] = matrixB[r][c] - matrixA[r - x][c - y] | ||
} | ||
|
||
println(matrixA.joinToString("\n") { it.joinToString(" ")}) |
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.
👍👍👍
val op: (Double, Double) -> Double = | ||
when (opC) { | ||
MUL -> { b, a -> a * b } | ||
DIV -> { b, a -> a / b } | ||
ADD -> { b, a -> a + b } | ||
SUB -> { b, a -> a - b } | ||
else -> { _, _ -> 0.0 } | ||
} |
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.
람다함수 멋있슴다!
println(st.last().let{ String.format("%.2f", it) }) | ||
} | ||
|
||
fun calc(n1: Double, n2: Double, opC: Char) { |
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.
ArrayDeque가 이미 calc에서 접근이 가능하기 때문에 굳이 n1, n2인지가 필요없을 것 같아요!!
DIV -> { b, a -> a / b } | ||
ADD -> { b, a -> a + b } | ||
SUB -> { b, a -> a - b } | ||
else -> { _, _ -> 0.0 } |
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.
_, _ 로 사용하지 않는 변수들을 명시하신 것이 좋은 것 같습니다!
matrixA[r][c] = matrixB[r][c] - matrixA[r - x][c - y] | ||
} | ||
|
||
println(matrixA.joinToString("\n") { it.joinToString(" ")}) |
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.
joinToString을 두 번 사용해서 출력 형식을 맞춘 부분이 이쁜 것 같습니다!
|
||
class 소병희_java_vs_cpp { | ||
companion object { | ||
const val UNDERSCORE = '_' |
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.
상수로 이쁘게 빼서 관리하시는 모습 잘 배웠습니다!
📌 from issue #41 📌
📋문제 목록📋