-
Notifications
You must be signed in to change notification settings - Fork 0
[우선순위 큐] 9월 17일 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
인적사항 이름: 조수아 학번: 2371060 과제 제출 기존 제출: 2075, 2607, 14235
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2607(p3)
수아님 안녕하세요 :3 구현문제 코드리뷰 드렸습니다.
주석을 꼼꼼히 달아주셔서 이해하기 편했습니다!
몇 가지 코멘트 남겨드렸어요. 질문이 있으시다면 언제든 편히 리뷰어를 호출해주세요~
int count = 0; | ||
for (int i = 0; i < n - 1; i++) { | ||
string testStr; | ||
cin >> testStr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3. 함수의 용도를 명확히 하기 위해 입출력은 메인에서만 해주는 것이 좋습니다~!
int tempAlpha[26]; | ||
copy(alpha, alpha + 26, tempAlpha); | ||
|
||
//testStr에 같은 알파벳이 얼마나 있는지 확인 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3. 이 부분은 initializeAlpha에서 사용된 로직과 거의 동일하네요! 이미 만들어둔 함수를 최대한 재사용해보는 쪽이 좋겠죠? 🤗
//targetStr가 testStr보다 한 글자 더 긴 경우 (testStr가 한 글자 추가된 경우) | ||
else if (targetLen - 1 == testLen && same == targetLen - 1) { | ||
return true; | ||
} | ||
//targetStr가 testStr보다 한 글자 더 짧은 경우 (testStr에서 한 글자가 삭제된 경우) | ||
else if (targetLen + 1 == testLen && same == targetLen) { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3. 글자가 더 많은지 짧은지에는 관계없이, 둘이 한 글자 차이가 나기만 하면 되니까 이 부분은 한번에 관리해주면 더 편할 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[우선순위 큐 이론 문제 코드 리뷰 완료]
2075(P2)
수아님 안녕하세요! 추석에 과제하시느라 고생 많으셨습니다! 배운 개념을 이용해서 깔끔하게 풀어주셨네요! 🥰
주석을 무척 꼼꼼하게 달아주셔서 쉽게 이해할 수 있었습니다!
몇 가지 코멘트 드렸습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!
//우선순위 큐(priority_queue)는 작은 수가 우선순위를 갖도록 설정 (최소 힙) | ||
priority_queue<int, vector<int>, greater<int>> pq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가장 작은 수를 꺼내려면 최소 힙을 써야 한다는 걸 잘 찾아주셨네요👍👍
//우선순위 큐의 가장 위에 있는 값이 n번째로 큰 값 | ||
return pq.top(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문제의 핵심을 잘 파악해주셨습니다👍👍
//큐의 크기가 n보다 작으면 새로운 숫자를 그대로 추가 | ||
if (pq.size() < n) { | ||
pq.push(num); | ||
} else { | ||
//큐의 크기가 n 이상일 때 | ||
//현재 숫자를 추가한 후 가장 작은 수를 제거 | ||
pq.push(num); | ||
pq.pop(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2. 현재 pq.push(num);
이 반복되고 있네요. 큐의 size를 확인하기 전에 push를 해도 될지 생각해보시면 좋을 것 같아요 😃😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(p3) 14235
우선순위 큐를 잘 사용해서 문제 잘 풀어주셨네요 ~ 구조적인 함수화를 통해 가독성 좋게 코드를 작성해주셨어요 ! 사소한 코멘트 몇 가지 남겨두었으니 참고하시면 좋을 것 같아요 고생하셨습니다 :)
//최대 힙을 전역 변수로 선언 | ||
priority_queue<int, vector<int>> maxHeap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(p3) 젼역 변수의 사용은 코드가 길어질 경우, 실수를 유발합니다. 협업에서도 지역변수로 사용할 수 있는 변수를 전역으로 정의해두면 혼선이 생길 수 있습니다 ~ 그래서 저희 튜터링에선 전역변수 사용은 정말 필요한 경우를 제외하고는 최대한 지양하도록 권장드리고 있습니다 :) 지역변수를 사용한 후에, 다른 함수에 쓰여야할 땐, 매개변수로 넘겨주도록 코드를 작성해보면 어떨까요?
void addGifts(int count) { | ||
for (int i = 0; i < count; i++) { | ||
int gift; | ||
cin >> gift; //사용자로부터 선물의 값을 입력 받음 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(p3) 입력과 출력을 함수에서 관리하게 될 경우, 함수의 용도가 굉장히 불명확해져요. 함수화를 하는 이유는 특정 로직의 코드를 반복해서 쓸 수 있도록 하기 위함인데, 입/출력을 포함하는 경우엔, 다른 곳에서 또 쓰기도 애매해지죠! 따라서 입력과 출력은 메인 함수에서만 하도록 권장드리고 있습니다 :)
인적사항
이름: 조수아
학번: 2371060
과제 제출
기존 제출: 2075, 2607, 14235