-
Notifications
You must be signed in to change notification settings - Fork 0
[구현 & 코너케이스] 3월 28일 -ing #6
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
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "03\uC6D4-22\uC77C---\uAD6C\uD604-&-\uCF54\uB108\uCF00\uC774\uC2A4"
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.
p1. 20923 문제에서 자료구조 관련 코멘트 남겼는데, 이 부분은 꼭 수정부탁드려요! 일단 함수화를 너무 잘해주셔서 코드 보기가 좋았습니다!! 최고예요 👍👍 수정하시거나, 질문 있으시면 저 리뷰어로 불러주세요~! 과제 하시느라 너무 수고하셨습니다 🥰
+ 더불어 5문제 모두 풀어주셨으므로 쿠폰 적립해두겠습니다! 😊
b %= 4; //지수를 최대 주기로 나눈 나머지 | ||
if (b == 0) b = 4; //값이 0이면 4번 제곱해야 함 | ||
cout << (int) pow(a % 10, b) % 10 << '\n'; //pow()는 double타입 반환 |
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.
오 주기마다 규칙을 찾아주셨네요! 완전 좋아요~~!! 👍👍👍 나중에 올라갈 샘플코드는 주기를 함수로 구해서 푸는 풀이니 참고해 보셔도 좋을 것 같아요~~!
vector<bool> v(21, false); //숫자가 집합 S에 있는지 체크하는 벡터 | ||
|
||
void processOp(string op, int x) { | ||
if (op == "add") { | ||
if (!v[x]) v[x] = true; //x를 추가 | ||
} else if (op == "remove") { | ||
if (v[x]) v[x] = false; //x를 삭제 | ||
} else if (op == "check") { | ||
cout << v[x] << '\n'; //x가 있으면 1, 없으면 0 출력 | ||
} else if (op == "toggle") { | ||
if (v[x]) v[x] = false; //x가 있으면 제거 | ||
else v[x] = true; //x가 없으면 추가 | ||
} | ||
} | ||
|
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. 전역변수 사용은 최대한 피해주는 게 좋아요! 함수도 void형이니 아예 main으로 넣어서 모두 처리해주면 더 좋을 것 같습니다~~!
//단어 하나를 받아서 그룹 단어인지 판별 | ||
bool isGroup(string str) { | ||
set<char> used_alp; //나온 알파벳 저장하는 set | ||
|
||
for (int i = 1; i < str.length(); i++) { //두 번째 인덱스부터 문자 순회, 길이 1인 단어는 무시 | ||
if (str[i - 1] != str[i]) { //앞 글자와 다른 문자이면 | ||
if (used_alp.count(str[i])) { //새로 나온 문자가 앞에서 이미 나왔으면 | ||
return false; | ||
} | ||
used_alp.insert(str[i - 1]); //연속이 끊긴 앞 문자를 set에 삽입 | ||
} | ||
} | ||
return true; | ||
} | ||
//힌트 확인해보니 set삽입연산 하는 것보단 크기 26인 bool타입 벡터로 확인하는 게 나았을 것 같긴 하네요.. |
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. 오! 함수화해서 너무너무 잘 풀어주셨어요!! 👍👍 넵 아무래도 set은 검색 삽입 삭제에 O(logN) 시간복잡도가 들기 때문에 벡터를 사용해서 true/false를 체크해주시는 편이 더 효율적입니다 🥰 그래도 로직은 거의 완벽해요!!! vector 사용으로 고쳐주셔도 좋을 것 같습니다!
//다이어트 연산, 일일 기초 대사량 변화를 고려하지 않을 땐 t = 0 | ||
void diet(int w0, int i0, int d, int i, int a, int t) { | ||
int w_later = w0; //체중 | ||
int b = i0; //일일 기초 대사량, 다이어트 전에는 일일 에너지 섭취량과 동일 | ||
for (int k = 0; k < d; k++) { //d일 동안의 체중, 기초 대사량 변화 계산 | ||
w_later += (i - (b + a)); //체중 변화 | ||
if (t >= 1 && abs(i - (b + a)) > t) { //기초 대사량 변화 역치 초과이면 일일 기초 대사량 변화, 두 번째 출력에서만 | ||
b += floor((i - (b + a)) / 2.0); | ||
} | ||
if (w_later <= 0 || b <= 0) { //체중, 일일 기초 대사량이 0 이하인 경우 사망 | ||
cout << "Danger Diet" << '\n'; | ||
return; //호출 종료 | ||
} | ||
} | ||
cout << w_later << ' ' << b << ' '; | ||
|
||
//요요 현상 발생 여부 확인, 두 번째 출력에서만 | ||
if (t >= 1) { | ||
if ((i0 - b) > 0) cout << "YOYO"; | ||
else cout << "NO"; | ||
} | ||
cout << '\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.
p2. 우선 출력은 main에서 해주시는 것이 좋습니다!! 함수는 기능을 분리하기 위해 사용하는 것이므로, 우선 return되는 값이 있는 것이 좋고, 또 연산의 중복을 방지하기 위해 사용하기도 해요. 이때, 함수 안에 출력이 있다면 불필요하게 계속 출력이 일어나는 일이 생길 수도 있겠죠! 따라서 디버깅을 위한 출력을 제외하곤 함수 내에는 출력이 없는 편이 좋습니다! 🥰 그리고 해당 함수는 void보다 체중과 기초대사량을 묶어서 리턴해주는 함수로 만들어도 좋을 것 같아요~!
//출력 | ||
diet(w0, i0, d, i, a, 0); | ||
diet(w0, i0, d, i, a, 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.
p2. 두 경우를 모두 해결할 수 있는 함수를 만들어주셨네요! 너무 좋지만, 사실 기초대사량 변화를 고려하지 않는 경우는 한 줄로 해결할 수 있어요 😉 기초 대사량이 변하지 않으니까, 해당 함수를 실행했을 때 무슨 연산이 반복되는지 식을 한 번 찾아볼까요!
//vector<deque<int>> vec = {do_deque, su_deque, do_ground, su_ground}; //벡터에 넣는 건 왜 안 될까요... | ||
|
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.
중괄호 안에 넣어주신 것들이 deque 형이라면 vector에 넣는 것 가능합니다!! 혹시 어떻게 하셨을 때 안된건지 말씀해주시면 같이 봐드릴께요!
map<int, deque<int>> m_deque; | ||
map<int, deque<int>> m_ground; |
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.
p1. 해당 문제는 검색이 중요한 문제가 아니기에, vector를 사용해주시는 편이 훨씬 효율적입니다 🥰
int p = i % 2; //카드를 뒤집는 사람 구분하는 인덱스 | ||
|
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.
p3. 차례는 도도(0) 아니면 수연(1)이기 때문에 다른 자료형을 사용하면 조금 더 간단하게 이 부분을 구현할 수 있어요! 😉
내용 & 질문
<기존 제출>