SMALL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include<iostream> #include<vector> #include<cmath> #include<algorithm> using namespace std; /* 8 / 3 = 2 ... 2 2 / 3 = 0 ... 2 9 / 3 = 3 ... 0 3 / 3 = 1 ... 0 10 /3 = 3 ... 1 3 / 3 = 1 ... 0 2 1 11 / 3= 3 ... 2 2 / 3 = 0 ... 2 3* 3 + 1* 3 12 / 3 =3 .. 0 3 3 / 3 =1 .. 0 3 13 / 3 = 4 ... 1 4 / 3 = 1 ... 1 1 / 3 = 0 ... 1 */ string change124(int no) { int a,b; string answer; while(no != 0) { a = no /3; b = no %3; if(b == 0) { a -=1; answer += '4'; }else answer += '0' + b; no = a; } reverse(answer.begin(), answer.end()); return answer; } int main() { int testNo = 10; string testAnswer = change124(testNo); cout<<testAnswer; } | cs |
LIST
'기타[etc] > 알고리즘' 카테고리의 다른 글
[알고리즘] DP-숫자 삼각형 (0) | 2018.03.28 |
---|---|
[알고리즘] 진법 변환 (0) | 2018.03.27 |
[알고리즘] 소수의 개수 찾기 - 에라토스테네스의 채 (0) | 2018.03.27 |
[알고리즘] DP- 땅따먹기 (0) | 2018.03.24 |
[알고리즘] DP-가장 큰 정사각형 찾기 (0) | 2018.03.23 |