3진법 뒤집기
https://school.programmers.co.kr/learn/courses/30/lessons/68935
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int solution(int n) {
string str = "";
while (n >= 1)
{
str += to_string(n % 3);
n /= 3;
}
reverse(str.begin(), str.end());
int iTemp(0);
for (int i = 0; i < str.size(); ++i)
{
iTemp += (str[i] - 48) * pow(3, i);
}
return iTemp;
}
'프로그래밍 > 코딩테스트' 카테고리의 다른 글
[프로그래머스] 같은 숫자는 싫어 (0) | 2023.06.22 |
---|---|
[프로그래머스] 1레벨 문제 (0) | 2023.06.21 |
[프로그래머스] 1레벨 여러문제 (0) | 2023.06.17 |
[프로그래머스] 1레벨 여러문제 (0) | 2023.06.11 |
[프로그래머스] 1레벨 문제 (0) | 2023.05.31 |
댓글