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

[장희직] - 괄호 회전하기, 후위 표기식, 사과나무, 캐슬 디펜스 #273

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

jhg3410
Copy link
Member

@jhg3410 jhg3410 commented Jun 2, 2024

📌 from issue #271 📌

📋문제 목록📋

괄호 회전하기: ✅, 
후위 표기식,: ⛔️ 
사과나무: ⛔️,
캐슬 디펜스: ✅

@jhg3410 jhg3410 added the 희직 label Jun 2, 2024
@jhg3410 jhg3410 self-assigned this Jun 2, 2024
Comment on lines +23 to +24
count2 += apple / 2
count1 += apple % 2
Copy link
Contributor

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 "+-*/()") {
Copy link
Contributor

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 == "(") {
Copy link
Contributor

Choose a reason for hiding this comment

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

항상 올바른 식만 주어져서 반드시 (가 있군요..

Copy link
Member

@soopeach soopeach left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!!!

Comment on lines +4 to +5
private val open = listOf('[', '(', '{')
private val close = listOf(']', ')', '}')
Copy link
Member

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

Choose a reason for hiding this comment

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

요기 혹시 스택이 비었을 때 안터지나요???

Copy link
Member

Choose a reason for hiding this comment

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

아 널이면 값 비교에서 그냥 false를 반환하겠군요

Copy link
Member Author

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

Choose a reason for hiding this comment

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

저는 chunked사용했었는데 toList로도 할 수 있군요

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅎㅎ 그렇슴다!!
image

fun solve() {
val expression = readln().toList().map { it.toString() }
expression.forEach {
if (it !in "+-*/()") {
Copy link
Member

Choose a reason for hiding this comment

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

문자열에서 in 으로 한 번에 처리하긴게 엄청 깔끔하고 좋네요!

Comment on lines +29 to +35
if (it in "*/") {
if (stack.isNotEmpty() && stack.last() in "*/") {
sb.append(stack.removeLast())
}
stack.add(it)
return@forEach
}
Copy link
Member

Choose a reason for hiding this comment

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

멋지네요!!!

@jhg3410 jhg3410 merged commit c6e6628 into main Jun 2, 2024
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