Skip to content
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

Merged
merged 5 commits into from
Nov 13, 2022

Conversation

bngsh
Copy link
Contributor

@bngsh bngsh commented Nov 13, 2022

📌 from issue #41 📌

📋문제 목록📋

Java vs C++: ✅
1,2,3 더하기 4: ⛔️(답 참고)
도어맨: ✅
배열 복원하기: ✅
후위 표기식2: ✅

@bngsh bngsh added the 병희 label Nov 13, 2022
Comment on lines +17 to +19
wait.indexOfFirst {
count += it
abs(count) > d + 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexOfFirst 신기하네요!! count가 계속 실행된다는 것을 병희님 덕분에 알게 되었습니다

Comment on lines +20 to +23
}.let { ans -> when (ans) {
-1 -> if (abs(count) == d + 1) println(wait.size - 1) else println(wait.size)
else -> println(ans - 1)
} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직이 넘 깔끔해서 감탄했습니다!! 차이에서 하나를 더 더한 걸 생각한게 놀라웠어요

Comment on lines +31 to +39
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

람다함수 사용 👍

Comment on lines +29 to +37
if (prev == UNDERSCORE) {
if (cur.isLowerCase()) {
sb.append(cur.uppercase())
}
else error()
}
else if (cur.isUpperCase()) {
sb.append("_${cur.lowercase()}")
}
Copy link
Member

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(" ")})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍👍

Comment on lines +31 to +38
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 }
}
Copy link
Member

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) {
Copy link
Member

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 }
Copy link
Member

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(" ")})
Copy link
Member

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 = '_'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수로 이쁘게 빼서 관리하시는 모습 잘 배웠습니다!

@bngsh bngsh merged commit 4ac14cc into main Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants