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

[정수론] 9월 2일 #3

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

[정수론] 9월 2일 #3

wants to merge 5 commits into from

Conversation

rahaaaiii
Copy link
Collaborator

@rahaaaiii rahaaaiii commented Sep 2, 2023

인적사항

학번 : 2271092
이름 : 이한선

과제제출

기존제출 : 1735, 2840, 6588
추가제출 :

Copy link

@kimhj010502 kimhj010502 left a comment

Choose a reason for hiding this comment

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

[정수론 구현 문제 코드 리뷰 완료]

2840(P2)

한선님 안녕하세요!
과제하시느라 수고 많으셨습니다!! 어려운 문제인데도 잘 풀어주셨네요! 🥰
코드에 대한 주석도 너무 좋았습니다 👍
몇 가지 사소한 코멘트 드렸습니다.
궁금한 점이 있으면 리뷰어를 호출해주세요!

int main()
{
//변수 선언
int N, K, sum=0;

Choose a reason for hiding this comment

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

P2. 알튜비튜에서 변수 이름은 스네이크 표기법으로 작성하도록 합니다! 클린코드 가이드를 확인해주세요~!


for(int i=0; i<K; i++){
cin>>w[i].n>>w[i].s;
sum+=w[i].n;

Choose a reason for hiding this comment

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

출력을 시작하는 인덱스를 따로 정의해줬군요! 아이디어 좋아요👍

string s="";
};

string wheelF(vector<wheel> &w, vector<string> &ans,int N, int K){//출력을 간단히 하기 위해 ans 벡터를 인자로 가져옴.

Choose a reason for hiding this comment

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

함수 분리 좋아요~!👍

using namespace std;

struct wheel{
int n;

Choose a reason for hiding this comment

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

P2. 스네이크 표기법을 활용하여 main 함수의 N과 K를 소문자 n, k로 정의하게 되면 여기서의 n과 겹치게 되겠네요! 다른 변수를 사용해주세요!


struct wheel{
int n;
string s="";

Choose a reason for hiding this comment

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

알파벳 하나가 입력으로 주어지기 때문에 string 자료형이 아닌 char형으로 정의해줘도 돼요!

if(ans[temp] != ""&&ans[temp]!=w[i].s){
return "!";
}
auto it=find(ans.begin(), ans.end(), w[i].s);//중복 제거를 안해주면 틀린다.
Copy link

@kimhj010502 kimhj010502 Sep 9, 2023

Choose a reason for hiding this comment

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

P2. find() 함수를 사용하여 알파벳 중복 체크를 해줬네요! 이 방법도 괜찮지만 find 연산의 시간복잡도는 O(n)으로 n이 커지게 되면 시간복잡도 측면에서 비효율적일 수 있어요! 알파벳 중복 확인 배열을 활용하는 방법도 있으니 참고해주세요~

string wheelF(vector<wheel> &w, vector<string> &ans,int N, int K){//출력을 간단히 하기 위해 ans 벡터를 인자로 가져옴.
int temp=0;
for(int i=0; i<K; i++){
temp = (temp+w[i].n) % N;

Choose a reason for hiding this comment

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

화살표의 위치를 잘 갱신해줬네요~👍

Comment on lines +24 to +28
for(int i=0; i<N; i++){
if(ans[i] == ""){
ans[i] = "?";
}
}

Choose a reason for hiding this comment

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

P2. main 함수에서 ans 벡터를 정의할 때 vector<char> ans(N, '?');로 해준다면 따로 이 과정을 거치지 않아도 되겠죠?

cin>>N>>K;

vector<wheel> w(K);//K만큼 할당 안해주고 값 입력받으면 for 문 안돌아간다.
vector<string> ans(N, "");

Choose a reason for hiding this comment

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

여기서도 마찬가지로 알파벳 하나가 입력으로 주어지기 때문에 string 자료형이 아닌 char형으로 정의해줘도 돼요!

cout<<str;
}
else{
int n=sum%N;//출력 시작 인덱스

Choose a reason for hiding this comment

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

P2. n을 여러번 사용해줬네요 코드의 가독성과 쉬운 유지보수를 위해 최대한 다른 변수로 정의해주는 게 좋아요!

Copy link
Contributor

@kwakrhkr59 kwakrhkr59 left a comment

Choose a reason for hiding this comment

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

[정수론 알고리즘 코드 리뷰 완료]
안녕하세요 한선님~ 정수론 필수 알고리즘 문제 코드리뷰 완료되셨습니다! 코드도 깔끔하고 주석도 아주 자세하게 써주셔서 인상깊었습니다😍 워낙 코드가 깔끔해서 특별히 드릴 말씀은 없었네요! 질문 있으시면 리뷰어로 호출해주세요😊 수고 많으셨습니다~

y%=x;
swap(x,y);
}
return y;
Copy link
Contributor

Choose a reason for hiding this comment

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

반복문을 사용해 유클리드 호제법을 구현해주셨네요! 잊지 않고 swap해주시는 것까지 완벽합니다😎

gcd=gcdIter(x, y);

x/=gcd;
y/=gcd;
Copy link
Contributor

Choose a reason for hiding this comment

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

통분하고 약분해주는 과정도 깔끔하네요😍

#include <cmath>
using namespace std;

const int RANGE=10000001;
Copy link
Contributor

Choose a reason for hiding this comment

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

입력 범위를 상수로 선언해주셨군요! 아주 좋습니다👍👍

is_prime[j]=false;
}
}
}
Copy link
Contributor

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.

3 participants