[백트래킹] 10월 15일#9
Open
seoyoung1214 wants to merge 5 commits intomainfrom
Open
Conversation
sforseohn
reviewed
Oct 30, 2024
Member
sforseohn
left a comment
There was a problem hiding this comment.
[백트래킹 구현 문제 코드 리뷰 완료]
2477(P2, P3)
서영님 안녕하세요! 시험 기간 직전이었는데 열심히 풀어주셨네요! 고생 많으셨습니다. 🥰
주석을 꼼꼼하게 달아주셔서 쉽게 이해할 수 있었습니다!
정석적으로 잘 구현해주셔서 크게 코멘트 드릴 내용은 없었습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!
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; |
Member
There was a problem hiding this comment.
P2. 6이 반복되고 있네요! 이렇게 특정 상수가 반복될 때 하드코딩하기보다는 상수 변수를 선언해서 사용하면 가독성도 좋아지고 실수할 일이 줄어듭니다 🥰
| int k; // 1m^2 당 참외의 개수 | ||
| cin >> k; | ||
|
|
||
| vector<pair<int, int>> edges(6); // 방향과 길이를 저장할 벡터 |
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; | ||
| } |
Member
There was a problem hiding this comment.
P2. 현재 메인함수에서 문제의 모든 기능을 구현하고 있죠. 영역을 구하는 부분을 함수로 빼서 재사용성을 높여 볼까요? 😊
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; |
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.
인적사항
이름 : 김서영
학번 : 2277040
문제풀이
기존 제출 : 14888, 15665, 2477, 2580, 프로그래머스_소수찾기