Skip to content
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

Week09 #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Week09 #9

wants to merge 3 commits into from

Conversation

SqueezeTheLemon
Copy link
Collaborator

이름: 김재이
학번: 2376071

제출: 14888, 2477, 15665

Copy link
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 on lines +6 to +62
int main() {
int n;
cin >> n;

vector <int> dir(6);
vector <int> len(6);

vector <pair <int, int>> v(6);

vector <int> is_used(5,0);

for (int i=0; i<6 ; i++){
int d;
int l;

cin >> d >> l;

dir[i]=d;
len[i]=l;

v[i]=make_pair(d,l);

//방향 나온 빈도 체크하기

is_used[d]++;

}

int total=1;
int minus=1;

vector <int> two;

for(int i=1; i<5 ; i++){
//한번만 나온 방향의 경우, 즉 전체 사각형의 크기를 먼저 구한다
if(is_used[i]==1){
for (int j=0 ; j<6 ; j++){
if(v[j].first==i){
total*=v[j].second;

if(j>=3) two.push_back(j-3);
else two.push_back (j+3);
}
}

}
}

minus=len[two[0]]*len[two[1]];

cout << (total-minus)*n;




return 0;
}
Copy link
Member

Choose a reason for hiding this comment

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

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

Comment on lines +10 to +13
vector <int> dir(6);
vector <int> len(6);

vector <pair <int, int>> v(6);
Copy link
Member

Choose a reason for hiding this comment

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

P2. 두 벡터와 int pair 중 하나만 써도 될 것 같네요! 🥰

Comment on lines +39 to +40
for(int i=1; i<5 ; i++){
//한번만 나온 방향의 경우, 즉 전체 사각형의 크기를 먼저 구한다
Copy link
Member

Choose a reason for hiding this comment

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

방향이 몇 개 나왔는지 세서 케이스를 분리해주셨군요! 좋습니다👍👍👍


vector <int> is_used(5,0);

for (int i=0; i<6 ; i++){
Copy link
Member

Choose a reason for hiding this comment

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

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

Comment on lines +46 to +54
if(j>=3) two.push_back(j-3);
else two.push_back (j+3);
}
}

}
}

minus=len[two[0]]*len[two[1]];
Copy link
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