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.
🧷 문제 링크
10993 별 찍기 - 18
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
재귀 사용해서 별 찍으면 되는 문제입니다.
🔍 풀이 방법
직선은 양 끝점에서 1씩 가운데로 움직이도록,
대각선은 거기에 x축 방향으로 ±1 하도록 반복문을 구성하여 한 번에
*을 찍었습니다.시작 점은 삼각형이 꽉 차는 사각형의 좌상단 모서리로 잡았습니다.
짝수의 경우 역삼각형이기 때문에 시작 좌표의
x값은 늘x+1이 되고홀수의 경우 높이의 절반이 되기 때문에
x + h / 2입니다.좌표의
y값은 항상 너비를 4로 나눈 값이 되어y + w / 4 + 1이 됩니다.이를 깊이가 1(가장 작은 삼각?형)이 될 때까지 반복합니다.
⏳ 회고
규칙 찾는 건 그다지 어렵지 않았는데 오른쪽 공백을 출력하면 안 된다는 사실을 늦게 알아서 시간이 좀 걸렸습니다.
재귀를 하는 과정에서 공백을 함께 넣어 오른쪽 공백을 아예 넣지 않는 것이 베스트겠지만
이미 로직이 다 나온 상태라 그냥 출력할 때 오른쪽 공백 제외하고 출력하도록 했습니다..