프로그래머스 - 3진법 뒤집기
2022. 8. 21. 15:11ㆍ코딩 공부 연습
반응형
훨씬 쉽게할 수 있을 것 같은데 좀 멍청하게 했다. 하지만 뭐 이정도야!
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int threefunc(int x)
{
long long tmp = 1;
for (int i = 0; i< x; i++)
tmp*=3;
return tmp;
}
int solution(int n) {
long long answer = 0;
long long tmpthree = 0;
while (n > 0)
{
tmpthree = tmpthree*10 + n%3;
n = n/3;
}
long long x = 0;
while ( tmpthree> 0)
{
answer = answer + (tmpthree%10) * threefunc(x);
tmpthree/=10;
x++;
}
return answer;
}
'코딩 공부 연습' 카테고리의 다른 글
백준 2468 안전영역 (0) | 2022.08.23 |
---|---|
백준 5427 불 (0) | 2022.08.22 |
프로그래머스 부족한 금액 계산하기 (0) | 2022.08.16 |
프로그래머스 최대공약수와 최소공배수 (0) | 2022.08.12 |
프로그래머스 소수 찾기 (0) | 2022.08.12 |