Notice
Recent Posts
Recent Comments
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags more
Archives
Today
Total
관리 메뉴

Share Garam's everyday life.

3진법 뒤집기 본문

알고리즘

3진법 뒤집기

가람스나이퍼님 (Joshua_Choi_Brother) 2021. 4. 21. 19:34

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int n) {
    int result = 0;
    int cn = n;
    
    while(cn!=0){
        int remain = cn % 3;
        result *= 3;
        result += remain;
        cn/=3;
    }
    
    return result;
}

'알고리즘' 카테고리의 다른 글

음양 더하기  (0) 2021.04.21
내적  (0) 2021.04.21
소수 만들기  (0) 2021.04.21
가운데 글자 가져오기  (0) 2021.04.21
알고리즘1  (0) 2018.03.17