주어진대로 구현하면 됨.
10진법을 3진법, reverse해서 3진법을 10진법으로 바꾸면 된다.
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
int answer = 0;
string temp = "";
for (int i = 3; n != 0; n /= i)
temp += (n % 3) + '0';
for (int i = temp.size() - 1, j = 1; i >= 0; i--, j *= 3)
answer += (temp[i] - '0') * j;
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 두 개 뽑아서 더하기 (0) | 2022.04.23 |
|---|---|
| [프로그래머스] (C++) LV1 예산 (0) | 2022.04.21 |
| [프로그래머스] (C++) LV1 약수의 개수와 덧셈 (0) | 2022.04.18 |
| [프로그래머스] (C++) LV1 실패율 (0) | 2022.04.17 |
| [프로그래머스] (C++) LV1 폰켓몬 (0) | 2022.04.16 |