Skip to content

[백트래킹] 10월 15일#9

Open
seoyoung1214 wants to merge 5 commits intomainfrom
week09
Open

[백트래킹] 10월 15일#9
seoyoung1214 wants to merge 5 commits intomainfrom
week09

Conversation

@seoyoung1214
Copy link
Copy Markdown
Collaborator

인적사항

이름 : 김서영
학번 : 2277040

문제풀이

기존 제출 : 14888, 15665, 2477, 2580, 프로그래머스_소수찾기

Copy link
Copy Markdown
Member

@sforseohn sforseohn left a comment

Choose a reason for hiding this comment

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

[백트래킹 구현 문제 코드 리뷰 완료]

2477(P2, P3)

서영님 안녕하세요! 시험 기간 직전이었는데 열심히 풀어주셨네요! 고생 많으셨습니다. 🥰
주석을 꼼꼼하게 달아주셔서 쉽게 이해할 수 있었습니다!

정석적으로 잘 구현해주셔서 크게 코멘트 드릴 내용은 없었습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!

Comment thread BOJ_2477.cpp
Comment on lines +35 to +37
// 작은 직사각형의 가로와 세로 찾기
int small_width = edges[(max_width_idx + 3) % 6].second;
int small_height = edges[(max_height_idx + 3) % 6].second;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2. 6이 반복되고 있네요! 이렇게 특정 상수가 반복될 때 하드코딩하기보다는 상수 변수를 선언해서 사용하면 가독성도 좋아지고 실수할 일이 줄어듭니다 🥰

Comment thread BOJ_2477.cpp
int k; // 1m^2 당 참외의 개수
cin >> k;

vector<pair<int, int>> edges(6); // 방향과 길이를 저장할 벡터
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pari 써주신 것 좋습니다~!

Comment thread BOJ_2477.cpp
Comment on lines +6 to +46
int main() {
int k; // 1m^2 당 참외의 개수
cin >> k;

vector<pair<int, int>> edges(6); // 방향과 길이를 저장할 벡터

// 방향과 길이 입력 받기
for (int i = 0; i < 6; i++) {
cin >> edges[i].first >> edges[i].second;
}

int max_width = 0, max_height = 0;
int max_width_idx = 0, max_height_idx = 0;

// 큰 직사각형의 가로와 세로를 찾기
for (int i = 0; i < 6; i++) {
if (edges[i].first == 1 || edges[i].first == 2) { // 동서 방향 (가로)
if (edges[i].second > max_width) {
max_width = edges[i].second;
max_width_idx = i;
}
} else if (edges[i].first == 3 || edges[i].first == 4) { // 남북 방향 (세로)
if (edges[i].second > max_height) {
max_height = edges[i].second;
max_height_idx = i;
}
}
}

// 작은 직사각형의 가로와 세로 찾기
int small_width = edges[(max_width_idx + 3) % 6].second;
int small_height = edges[(max_height_idx + 3) % 6].second;

// 큰 직사각형의 넓이에서 작은 직사각형의 넓이를 빼서 참외밭의 넓이를 구함
int area = (max_width * max_height) - (small_width * small_height);

// 참외밭의 넓이에 1m^2 당 참외의 개수인 k를 곱해 참외의 총 개수를 출력
cout << area * k << "\n";

return 0;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2. 현재 메인함수에서 문제의 모든 기능을 구현하고 있죠. 영역을 구하는 부분을 함수로 빼서 재사용성을 높여 볼까요? 😊

Comment thread BOJ_2477.cpp
Comment on lines +36 to +37
int small_width = edges[(max_width_idx + 3) % 6].second;
int small_height = edges[(max_height_idx + 3) % 6].second;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

규칙성을 발견해주셨네요! 좋습니다👍👍

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