Skip to content

양혜림/4주차#10

Open
hyellm wants to merge 1 commit into
YEOUL0520:mainfrom
hyellm:hyelim2
Open

양혜림/4주차#10
hyellm wants to merge 1 commit into
YEOUL0520:mainfrom
hyellm:hyelim2

Conversation

@hyellm
Copy link
Copy Markdown

@hyellm hyellm commented Oct 4, 2024

[4주차] 3진법 뒤집기 (68935) / Lv. 1
https://school.programmers.co.kr/learn/courses/30/lessons/68935

  • 정적 배열로 선언했다가 동적 배열로 코드를 수정하였는데, 자연수 n의 범위가 정해져 있으니 이를 3진법으로 전환하는 방법으로 최댓값을 찾아 그 최댓값의 정적 배열로 선언하는 건 어떨까 하는 생각도 했다.
  • pow() 함수를 사용하여 코드를 작성했는데, 이 방법 말고 비트 연산을 통해 3의 거듭제곱을 직접 계산하는 방법도 있을 것 같다. 근데 성능 면에서는 pow() 함수를 써도 큰 차이가 없지 않을까... 하는 생각이 들긴 하지만 상대적으로 편리하니까 그대로 썼는데, pow() 함수는 일반적으로 부동소수점 연산을 수행하므로 성능이 떨어질 수도 있다고 하긴 하더라... 🫠

[4주차] 같은 숫자는 싫어 (12906) / Lv. 1
https://school.programmers.co.kr/learn/courses/30/lessons/12906

  • 코드 내에 사용된 resize() 같은 것들 대신 push_back(), back()을 활용하는 방법도 있을 것 같음

Comment thread main_12906.cpp
int p = 0;
int arr_size = arr.size();

answer.resize(arr_size); // answer의 크기를 arr의 크기로 설정
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

resize 쓰는거 신기한데? 스터디 할때 어떻게 동작하는 함수인지 설명해주면 좋을 것 같음!

Comment thread main_68935.c
#include <math.h> // pow()

int solution(int n) {
int* arr = (int*)malloc(n * sizeof(int)); // 동적 배열 할당 :: int arr[100];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

오랜만에 보는 동적배열,, 저도 이 방법을 사용하엿는데요,(ㅋㅋ

Comment thread main_68935.c
int i = 0, cal = 0, answer = 0;

// 3진수 계산
while (n >= 3) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

n != 0 이 조건 쓰면 변환 후 마지막 자리값을 따로 넘겨줄 필요 없을 것 같음!

Comment thread main_12906.cpp
int p = 0;
int arr_size = arr.size();

answer.resize(arr_size); // answer의 크기를 arr의 크기로 설정
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

resize 신기해요. answer 초기화할때 크기 지정하면 안써도 되나요?

Comment thread main_68935.c
arr[i] = n; // 변환 후의 마지막 자리값 넘겨주기

// 반전시키지 않아도 거꾸로 들어있으므로 그대로 10진법 변환
for (; i >= 0; i--) {
Copy link
Copy Markdown

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