๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int solution(int n) {
int answer = 0;
string bit = "";
while(n!=0){
int mod = n%3;
bit+=mod+'0';
n/=3;
}
reverse(bit.begin(),bit.end());
for(int i=0; i<bit.length(); i++){
if(bit[i]!='0') answer+= pow(3,i)*(bit[i]-'0');
}
return answer;
}
ํ์ด(13๋ถ)
์ง๋ฒ ๋ณํ์ ๋ํด์ ์๋๋ ๋ชจ๋ฅด๋๋๋ฅผ ๋ฌผ์ด๋ดค๋ ๊ฐ๋จํ ๊ตฌํ ๋ฌธ์ ์์ต๋๋ค.
์ ํ์ด๋๋ก ์ง๊ด์ ์ผ๋ก ๋ฐ๋ก ๊ตฌํํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ฉ๋ด ๋ฆฌ๋ด์ผ(Level 2) (2) | 2022.04.13 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ ์ฐพ๊ธฐ(Level 2) (0) | 2022.04.13 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - [1์ฐจ] ๋น๋ฐ ์ง๋(Level 1) (0) | 2022.04.13 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์์ ๋ง๋ค๊ธฐ(Level 1) (0) | 2022.04.11 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์(Level 1) (0) | 2022.04.10 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํคํจ๋ ๋๋ฅด๊ธฐ(Level 1) (0) | 2022.04.10 |
๋๊ธ