-
Notifications
You must be signed in to change notification settings - Fork 0
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
[정렬] 9월 7일 #1
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uC815\uB82C"
[정렬] 9월 7일 #1
Conversation
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. 우선 코드 너무 잘 짜주셨어요!!! 몇 몇 문제만 제외하면 거의 완벽합니다 👍 그리고 모든 과제를 풀어주셨네요! 쿠폰 적립해둘께요!!
아래에도 말씀드린 것처럼 1316번과 1431, 1946 번만 수정 후 리뷰어로 저 다시 호출해주시면 감사하겠습니다!
다음번엔 주석도 달아주시면 너무 좋을 것 같아요. 넘 수고하셨습니다~!!
9월 7일 - 정렬/1026.cpp
Outdated
int n; | ||
cin >> n; | ||
int a[n], b[n]; | ||
bool check[n]; |
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.
배열도 좋지만, c++에 익숙해지기 위해 vector 사용도 추천드립니다!
9월 7일 - 정렬/1026.cpp
Outdated
|
||
int sum = 0; | ||
for(int i=0; i<n; i++){ | ||
sum += a[i]*b[n-i-1]; |
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.
오오 둘 다 오름차순으로 해서 인덱스를 거꾸로 접근하신 거 좋네요 ! 👍 greater<>() 을 활용하여 내림차순 정렬을 해봐도 좋을 것 같아요!
9월 7일 - 정렬/10994.cpp
Outdated
int main(){ | ||
int n; | ||
cin >> n; | ||
int length = 1+(n-1)*4; |
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.
괄호를 풀어 계산하면 식을 더 단순화 시킬 수 있을 것 같아요 👍
9월 7일 - 정렬/10994.cpp
Outdated
cout << star[i][j]; | ||
} | ||
else | ||
cout << " "; |
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.
2차원 벡터를 사용하여 처음 선언 시 " "로 초기화하면 star[i][j] 로 한 번에 출력이 가능해요! 2차원 벡터로 풀이해 보시는 걸 추천드려요 👍
} | ||
} | ||
|
||
solve(x+2, y+2, start_len, length-4, star); |
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.
테두리 별이 4씩 줄어든다는 규칙을 아주 잘 파악하셨군요 ! 👍 재귀로 너무 잘 구현해주셨어요
9월 7일 - 정렬/1431.cpp
Outdated
|
||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < srl[i].length; j++) { | ||
if (srl[i].num.at(j) >= 48 && srl[i].num.at(j) <= 57) |
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.
isdigit 함수에 대해 알아보면 좋을 것 같아요! 또한 아스키코드를 바로 사용하는 건 실수의 가능성이 있으니 '0' 과 '9' 로 사용하시는 걸 추천드려요!
9월 7일 - 정렬/1431.cpp
Outdated
}; | ||
|
||
bool cmp(const serial &i1, const serial &i2){ | ||
if(i1.num.length() != i2.num.length()) |
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. 구조체에 length 변수를 만들어주셨는데 num에 접근하신 후 length() 함수를 사용하셨네요! 둘 중 하나만 하셔야 될 것 같아요. 이왕이면 구조체 사용없이 string num만 사용하시는 걸 추천드립니다! 그러면 인덱스에 계속 접근하는 부분도 깔끔해질 것 같아요. 지금 sum값을 미리 저장하시느라 구조체 사용을 하신 것 같은데, sum을 구하는 함수를 따로 만드시면 이 부분도 해결 될 것 같아요!
9월 7일 - 정렬/1946.cpp
Outdated
|
||
int solution(int n) { | ||
vector<pair<int, int>> v; | ||
v.assign(n, {}); |
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.
선언 시 한번에 초기화하는 걸 추천드려요!
9월 7일 - 정렬/1946.cpp
Outdated
|
||
for(int i=0; i<n; i++){ | ||
cin >> v[i].first >> v[i].second; | ||
} |
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. 가급적 입력은 main에서 처리해주시는 게 좋아요. vector를 함수의 인자로 넘기는 방법을 사용해주세요! 아래 정렬 부분도 마찬가지로 main 에서 해주시는 게 좋아요!
지금 함수에 너무 많은 기능이 담겨있어요. 모듈화를 하는 이유는 그 기능만 담아서 편리하게 사용하기 위해서인데, 작성해주신 solution 함수는 입력 + 정렬 + 문제 핵심 풀이 가 한번에 이루어지고 있죠. 지금은 문제가 되지 않지만 더 긴 코드를 작성할 때, 함수 이름만 보고 solution 함수를 계속 호출한다면 어떻게 될까요? 이 부분 꼭 함수에 문제 핵심 풀이만 담기도록 수정 부탁드려요!
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.
꼼꼼한 리뷰 정말 감사합니다!
ans[i] = solution(v, n);
1946번 여기서 궁금한 점이 있는데요, 말해주신대로 수정을 하다가 ans[t]를 배열로 했을 때는 오류가 나는데 벡터로 했을 때는 오류가 아니더라고요. 이유가 뭔지 잘 모르겠어요!
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.
엇 말씀해주신대로 벡터만 배열 or 배열을 벡터로 바꾼거라면 오류가 나거나 달라질 수 없습니다! IDE에 옮겨서 확인도 해봤는데 저는 괜찮았어요..! 혹시 ans[t]를 배열 사용 시, 다른 코드 부분이 달랐던 건 아닐까요..? 그 때의 전체 코드를 주시면 확인해드릴께욥!!
++ 지금 리뷰하면서 발견한건데요..! 혹시 solution 함수로 넘기는 부분에서의 매개변수 타입을 일치시키지 않은 거려나요....!? 지금으로선 이 가능성이 가장 클 것 같아요!
++ 엇 그런데 또 ans만 배열로 바꾸시고, v는 계속 벡터로 사용하셨다면 매개변수 부분도 문제가 되진 않았을 것 같은데요...우선 말씀하신대로라면 오류가 안나야 하는게 맞습니다!!
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.
죄송합니다 다시 해보니까 오류가 없습니다ㅜㅜ
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.
아핫 다행이에요!!!!
9월 7일 - 정렬/1946.cpp
Outdated
int temp = v[0].second; | ||
for(int i=1; i<n; i++){ | ||
if(v[i].second > temp) | ||
count--; |
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.
오! 불합자를 찾아내는 풀이를 생각해주셨군요. 지금도 좋지만 합격자를 찾는 풀이로 하면 if else로 나누지 않고 아래 코드를 바로 합칠 수 있어요!
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.
너무 잘해주셨네요!!!!! 머지하셔도 될 것 같아요~! 추가로 수정하시고 싶으면 수정하셔도 좋아요! 넘 수고하셨습니다!!
if (check[ch - 'a']) | ||
return false; | ||
check[ch-'a'] = true; | ||
while(s[j+1] == ch) { |
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.
오오 함수화와 O(n) 풀이로 너무 잘 해주셨어요!!! 👍 지금처럼 while문으로 한 번에 같은문자를 처리하는 것도 좋지만, 겉에 for문에서 인덱스 증가가 이루어지고 있으므로 이 점을 활용하여 여기서 if문 + continue 로 처리를 하는 것도 좋아요~!
bool cmp(const string &i1, const string &i2){ | ||
if(i1.length() != i2.length()) | ||
return i1.length() < i2.length(); | ||
if(sum(i1) != sum(i2)) |
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.
👍👍👍
9월 7일 - 정렬/1946.cpp
Outdated
|
||
sort(v.begin(), v.end()); | ||
|
||
ans[i] = solution(v, n); |
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.
👍👍👍
또한 지금 테스트케이스 수만큼의 ans를 계속 저장해주셨는데, 이것도 좋지만 변수로 선언해서 바로바로 ans를 출력해도 괜찮아요!!!! 이렇게하면 마지막 출력을 위한 for문도 사용하지 않아도 되겠죠? 😊
리뷰해주시면 감사하겠습니다!!