웅재의 코딩세상
[프로그래머스] 3진법 뒤집기 본문
- 풀이
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int solution(int n) {
int answer = 0;
vector<int> arr;
while(n!=0){
arr.push_back(n%3);
n /=3;
}
int j = arr.size();
for(int i=0; i<j; i++){
answer = answer + arr[j-i-1] * pow(3,i);
}
return answer;
}
반응형
'코딩테스트 > 프로그래머스 - LV 1' 카테고리의 다른 글
[프로그래머스] 직사각형 별찍기 (0) | 2024.02.09 |
---|---|
[프로그래머스] 예산 (0) | 2024.02.09 |
[프로그래머스] 내적 (0) | 2024.02.09 |
[프로그래머스] 음양 더하기 (0) | 2024.02.09 |
[프로그래머스] 약수의 개수와 덧셈 (0) | 2024.02.09 |