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

[장희직] - 게임, 연산자 끼워넣기, 디스크 컨트롤러, A와 B #177

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
solve A와 B
jhg3410 committed Sep 18, 2023
commit 9f420d9602f4ebaffff65f7eee212bc92499cb92
36 changes: 36 additions & 0 deletions src/main/kotlin/heejik/45week/A와 B.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package heejik.`45week`

class `AB` {

private lateinit var origin: StringBuilder
private lateinit var goal: StringBuilder

fun solve() {
setting()
change().run {
println(this)
}
}

private fun setting() {
origin = StringBuilder(readln())
goal = StringBuilder(readln())
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

스트링빌더 아이디어 굿이네요,,,delete해주면 될걸 머리 싸매고 인덱스 계산을 했다니 ㅠㅠ

}

private fun change(): Int {
while (origin.length != goal.length) {
if (goal.last() == 'A') {
goal.deleteAt(goal.lastIndex)
Copy link
Member

Choose a reason for hiding this comment

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

그러게요.. deleteAt 야무지네요

} else {
goal.deleteAt(goal.lastIndex)
goal.reverse()
}
}
Comment on lines +21 to +28
Copy link
Member

Choose a reason for hiding this comment

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

오.. 깔끔깔끔


return if (origin.contentEquals(goal)) 1 else 0
}
}

fun main() {
`AB`().solve()
}