Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/7490
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
1 ~ N 까지의 수를 오름차순으로 쓴 수열이 있을 때
각 숫자들 사이에 +(덧셈), -(뺄셈), 공백(이어붙이기) 를 집어넣어서
수열 전체의 합이 0이 되게 하는 모든 경우의 수를 ASCII 순서에 따라서 출력하는 문제입니다.
🔍 풀이 방법
N의 크기가 크지 않기 때문에 모든 경우의 수를 구했습니다.
입력 순서는 ASCII 순서에 따라서 공백 + - 순으로 하였고
N까지 모든 숫자를 다 넣은 경우에 그 수식을 계산했습니다.
계산하는 방식으로는 모든 공백을 제거하고 (공백을 제거하면 공백 연산이 자동으로 수행됩니다)
이후 + 또는 - 를 구분자로 하여 토큰을 나눠서 계산했습니다.
결론적으로 위 값이 0이 되면 string 값에 넣어주고 마지막에 출력했습니다.
⏳ 회고
조금 만만하게 풀기 시작했다가 생각보다 애먹었습니다.
특히 공백을 처리하는 과정에서 replaceall이 생각 안나서 어떻게 푸나 고민을 많이 했던 것 같습니다.