Skip to content

1913문제(달팽이) 다른 풀이#5

Open
tryterry wants to merge 1 commit intomainfrom
b_1913
Open

1913문제(달팽이) 다른 풀이#5
tryterry wants to merge 1 commit intomainfrom
b_1913

Conversation

@tryterry
Copy link
Copy Markdown
Collaborator

@tryterry tryterry commented Feb 6, 2025

1913번 문제 기존 코드 수정,

1913번 문제 (달팽이) 다른 풀이 추가했습니다.

@tryterry tryterry requested a review from imcheck February 6, 2025 11:17
@tryterry tryterry self-assigned this Feb 6, 2025
x = half - i - 1;
y = half - i;
for (int j = 0; j < 4; j++) { // 상, 우, 하, 좌 (4번 반복)
for (int k = 0; k < step; k++) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

for 안에 if, else구문은 중요도나 비중이 높은 순서대로 적어주는게 코드가 좀 더 직관적이고 읽기 좋아
이거 같은 경우는 if 가 마지막 한번만 실행되고 대부분은 else가 실행되기 때문에 사실 순서를 바꾸는게 좋고 더 나아가 아래처럼 아예 if, else를 안쓰는게 가장 좋은 거 같아

for (int k = 0; k < step-1; k++) {
    arr[x][y] = ++count;
    x += dx[v];
    y += dy[v];
}
// 방향 전환
x += vx[v];
y += vy[v];

이게 좀 더 직관적이고 깔끔한거 같아.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants