[스택_큐_덱] 8월 27일#1
Conversation
sforseohn
left a comment
There was a problem hiding this comment.
[스택, 큐, 덱 이론 문제 코드 리뷰 완료]
4949(P2, P3)
가은님 안녕하세요! 과제하시느라 수고 많으셨습니다! 어려운 문제인데도 잘 풀어주셨네요! 🥰
다만, 코드에 대한 간단한 주석이 있으면 더 좋을 것 같아요 😎
몇 가지 코멘트 드렸습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!
| int main() { | ||
| ios::sync_with_stdio(false); | ||
| cin.tie(NULL); cout.tie(NULL); | ||
|
|
||
| string str; | ||
|
|
||
| while (true) { | ||
| getline(cin, str); | ||
|
|
||
| if (str == ".") break; | ||
|
|
||
| stack<char> check; | ||
| bool isBalanced = true; | ||
|
|
||
| for (char ch : str) { | ||
| if (ch == '(' || ch == '[') { | ||
| check.push(ch); | ||
| } else if (ch == ')') { | ||
| if (check.empty() || check.top() != '(') { | ||
| isBalanced = false; | ||
| break; | ||
| } | ||
| check.pop(); | ||
| } else if (ch == ']') { | ||
| if (check.empty() || check.top() != '[') { | ||
| isBalanced = false; | ||
| break; | ||
| } | ||
| check.pop(); | ||
| } | ||
| } | ||
|
|
||
| if (!check.empty()) { | ||
| isBalanced = false; | ||
| } | ||
|
|
||
| if (isBalanced) { | ||
| cout << "yes\n"; | ||
| } else { | ||
| cout << "no\n"; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
P2. 현재 메인함수에서 많은 기능을 처리하고 있어요. 주요 기능을 함수화해두면 다른 곳에서도 재사용할 수 있답니다! 괄호의 대칭을 확인하는 별도의 함수를 만들고 메인함수는 이 함수를 호출하여 결과만 출력하도록 만들어볼까요? 🥰🥰
| if (ch == '(' || ch == '[') { | ||
| check.push(ch); | ||
| } else if (ch == ')') { | ||
| if (check.empty() || check.top() != '(') { | ||
| isBalanced = false; | ||
| break; | ||
| } | ||
| check.pop(); | ||
| } else if (ch == ']') { | ||
| if (check.empty() || check.top() != '[') { |
There was a problem hiding this comment.
스택에 넣고 빼는 경우를 깔끔하게 잘 분리해주셨네요🤗🤗
| while (true) { | ||
| getline(cin, str); | ||
|
|
||
| if (str == ".") break; |
There was a problem hiding this comment.
P2. 중괄호가 없으면 코드를 수정할 일이 생길 때 불편할 수 있어요. 특히, 협업할 때는 나중에 추가한 중괄호로 인해 git에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍
| if (str == ".") break; | ||
|
|
||
| stack<char> check; | ||
| bool isBalanced = true; |
There was a problem hiding this comment.
P3. 변수명은 스네이크 코드 형식을 따라주세요!
int hello_world; // 변수
int helloWorld() // 함수
const int HELLO_WORLD // 상수
flowing1ife
left a comment
There was a problem hiding this comment.
[스택, 큐, 덱 구현 코드리뷰 완료]
1158(P2)
코드 리뷰 완료하였습니다 !
전체적으로 주석을 추가해서 코드의 가독성을 높이면 더욱 좋을 것 같습니다 ㅎㅎ
| while (!q.empty()) { | ||
| for (int i = 1; i < k; ++i) { | ||
| q.push(q.front()); | ||
| q.pop(); | ||
| } | ||
|
|
||
| cout << q.front(); | ||
| q.pop(); | ||
|
|
||
| if (!q.empty()) { | ||
| cout << ", "; | ||
| } | ||
| } |
There was a problem hiding this comment.
P2
알튜비튜에서는 main에서는 입출력만 다루는 것을 권장드리고 있어요 !
다음처럼 요세푸스 순열을 만드는 로직은 따로 함수로 빼면 좋을 것 같습니다 ㅎㅎ
No description provided.