Skip to content

[스택_큐_덱] 8월 27일#1

Open
gaeun0nueag wants to merge 3 commits intomainfrom
week2
Open

[스택_큐_덱] 8월 27일#1
gaeun0nueag wants to merge 3 commits intomainfrom
week2

Conversation

@gaeun0nueag
Copy link
Copy Markdown
Collaborator

No description provided.

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.

[스택, 큐, 덱 이론 문제 코드 리뷰 완료]

4949(P2, P3)

가은님 안녕하세요! 과제하시느라 수고 많으셨습니다! 어려운 문제인데도 잘 풀어주셨네요! 🥰
다만, 코드에 대한 간단한 주석이 있으면 더 좋을 것 같아요 😎
몇 가지 코멘트 드렸습니다.
궁금한 점이 있다면 리뷰어를 호출해주세요!

Comment thread week2/no4949
Comment on lines +8 to +52
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;
}
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 week2/no4949
Comment on lines +23 to +32
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() != '[') {
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.

스택에 넣고 빼는 경우를 깔끔하게 잘 분리해주셨네요🤗🤗

Comment thread week2/no4949
while (true) {
getline(cin, str);

if (str == ".") break;
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. 중괄호가 없으면 코드를 수정할 일이 생길 때 불편할 수 있어요. 특히, 협업할 때는 나중에 추가한 중괄호로 인해 git에서 충돌이 날 수 있답니다...!! 😱 코드가 한 줄이더라도 중괄호 넣으시는 걸 권장드립니다👍

Comment thread week2/no4949
if (str == ".") break;

stack<char> check;
bool isBalanced = true;
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.

P3. 변수명은 스네이크 코드 형식을 따라주세요!

int hello_world;      // 변수
int helloWorld()      // 함수
const int HELLO_WORLD // 상수

Copy link
Copy Markdown

@flowing1ife flowing1ife left a comment

Choose a reason for hiding this comment

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

[스택, 큐, 덱 구현 코드리뷰 완료]
1158(P2)


코드 리뷰 완료하였습니다 !
전체적으로 주석을 추가해서 코드의 가독성을 높이면 더욱 좋을 것 같습니다 ㅎㅎ

Comment thread week2/no1158
Comment on lines +21 to +33
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 << ", ";
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2
알튜비튜에서는 main에서는 입출력만 다루는 것을 권장드리고 있어요 !
다음처럼 요세푸스 순열을 만드는 로직은 따로 함수로 빼면 좋을 것 같습니다 ㅎㅎ

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.

3 participants