-
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
[장희직] - 괄호 회전하기, 후위 표기식, 사과나무, 캐슬 디펜스 #273
Conversation
count2 += apple / 2 | ||
count1 += apple % 2 |
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.
오 다시 생각해보니 3의 배수면 3으로 나눈 몫이 물을 주는 횟수가 되니까 홀수가 그 횟수를 초과하면 불가능한가봐요
fun solve() { | ||
val expression = readln().toList().map { it.toString() } | ||
expression.forEach { | ||
if (it !in "+-*/()") { |
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.
헐 그냥 스트링으로 해도 in 연산이 되는군요;;
if (it == ")") { | ||
while (true) { | ||
val last = stack.removeLast() | ||
if (last == "(") { |
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.
항상 올바른 식만 주어져서 반드시 (가 있군요..
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.
고생하셨습니다!!!
private val open = listOf('[', '(', '{') | ||
private val close = listOf(']', ')', '}') |
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 (c in open) { | ||
stack.append(c) | ||
} else { | ||
if (close.indexOf(c) == open.indexOf(stack.lastOrNull())) { |
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.
요기 혹시 스택이 비었을 때 안터지나요???
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.
아 널이면 값 비교에서 그냥 false를 반환하겠군요
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 sb = StringBuilder() | ||
|
||
fun solve() { | ||
val expression = readln().toList().map { it.toString() } |
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.
저는 chunked사용했었는데 toList로도 할 수 있군요
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.
fun solve() { | ||
val expression = readln().toList().map { it.toString() } | ||
expression.forEach { | ||
if (it !in "+-*/()") { |
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.
문자열에서 in 으로 한 번에 처리하긴게 엄청 깔끔하고 좋네요!
if (it in "*/") { | ||
if (stack.isNotEmpty() && stack.last() in "*/") { | ||
sb.append(stack.removeLast()) | ||
} | ||
stack.add(it) | ||
return@forEach | ||
} |
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 #271 📌
📋문제 목록📋