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

[브루트포스] 09월 22일 #6

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

[브루트포스] 09월 22일 #6

wants to merge 2 commits into from

Conversation

songing01
Copy link
Contributor

내용 & 질문

과제 제출합니다!

<기존 제출>

문제 번호 14888, 2858

<추가 제출>

x

Copy link

@dbswn dbswn left a comment

Choose a reason for hiding this comment

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

P2 14888 코드 리뷰 완료
안녕하세요 지민님!😊😊 코드도 너무 깔끔하고 주석도 작성해주셔서 리뷰 드리기 너무 좋았습니다!!! 또 코드 로직도 너무 좋았고 전역변수 관리도 잘해주시고 여러 사소한 부분에서 생각하신 부분이 잘 보여서 너무 좋았습니다!👍👍 너무 수고하셨어요!

간단한 코멘트 달았으니, 확인 부탁 드립니다 !수정하신 부분 있으시면 리뷰어로 불러주셔도 좋습니다! 수고 많으셨습니다.감사합니다. 🤗🤗

Comment on lines +5 to +6
//각 경우에 연산 최대 10번 수행. 경우는 4^6 보다 작음( 4 중복 순열 6)
//>>연산은 4만회 정도이므로 브루트포스로 구할 수 있다.
Copy link

Choose a reason for hiding this comment

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

브루트포스로 풀 수 있다고 확인해주시는 거 너무 좋습니다 👍👍

Comment on lines +78 to +79
cout << getMaxAndMin(n, num, opArr).first << "\n";
cout << getMaxAndMin(n, num, opArr).second;
Copy link

Choose a reason for hiding this comment

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

P2
함수를 두 번 호출하면 그만큼 시간이 더 오래 걸린답니다! 함수의 리턴 결과를 변수에 저장해보면 어떨까요?

Comment on lines +32 to +36
if (result > max_min.first) {
max_min.first = result;
}
if (result < max_min.second) {
max_min.second = result;
Copy link

Choose a reason for hiding this comment

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

P2
이 부분은 iostream에서 제공하는 max, min 함수를 이용하면 코드를 줄일 수 있을 것 같네요!

if (result < max_min.second) {
max_min.second = result;
}
} while (next_permutation(opArr.begin(), opArr.end()));
Copy link

Choose a reason for hiding this comment

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

next_permutation으로 로직 짜신 거 재귀보다 더 시간 효율이 좋은 것 같아 너무 좋은 것 같아요! 👍👍저는 생각하지 못했던 방식인데 잘 배워갑니다!!😊 샘플 코드에는 재귀를 활용한 방법이 올라갔으니 확인 부탁드려요~!

Comment on lines +22 to +29
if (opArr[i - 1] == '+') {
result += num[i];
} else if (opArr[i - 1] == '-') {
result -= num[i];
} else if (opArr[i - 1] == '*') {
result *= num[i];
} else if (opArr[i - 1] == '/') {
result /= num[i];
Copy link

Choose a reason for hiding this comment

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

P2
연산자에 따라서 계산하는 부분을 함수화 해보는 것은 어떨까요?

}

//연산 기호를 배열에 나열하기
vector<char> opArr;
Copy link

Choose a reason for hiding this comment

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

P3
연산 기호를 정말 char 형으로 정해 주셨네요! 코드에서 연산자의 역할은 어떤 연산을 할 지 정해주는 거죠! 꼭 연산 기호 자체를 사용할 필요 없이 구분이 되는 형식으로만 정해주셔도 좋을 것 같습니다!

const int MAX = 1e9;
const int MIN = -1e9;

pair<int, int> getMaxAndMin(int n, vector<int> &num, vector<char> &opArr) {
Copy link

Choose a reason for hiding this comment

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

P3
num 벡터는 함수 안에서 변경되면 안 될 것 같네요! 이럴 때 어떤 처리를 해줘야 할까요?

Copy link

@junghk0115 junghk0115 left a comment

Choose a reason for hiding this comment

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

안녕하세요 지민님!:)
코드 잘봤습니다~!! 👍
함수화 및 관련해서 알아두면 좋을 자료형에 대해 코멘트 남겨드렸으니 참고해서 학습하시면 좋을 것 같습니다!
과제하시느라 수고 많으셨어요~

Comment on lines +13 to +24
for (int i = 3; i <= sqrt(size); i++) {
//갈색은 항상 1개 이상, 빨강은 항상 8개 이상이므로 각 l,w가 3이상 이어야한다.
if (size % i == 0) {
l = max(i, size / i);
w = min(i, size / i);
if (r + 4 == (w + l) * 2){
cout << l << ' ' << w;
break;
}
}

}

Choose a reason for hiding this comment

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

p2. 해당 부분은 문제풀이의 핵심부분이니 함수화를 해주시는 것을 권장드립니다.
또한 함수화를 해주시는 과정에서 출력 부분인 cout코드는 따로 빼서 함수화 해야한다는 점을 유의해주세요! 출력 부분은 문제풀이 안에 함께 포함 되어 있는 것 보다 main에 작성하는 것을 권장드립니다.

정수 두 개를 다루는 것이 낯설어 함수화하는 것에 어려움이 있으시다면 c++의 pair 자료형에 대해 알아보시면 좋을 것 같습니다!

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