Algorithm/Programmers
[Programmers/C++] 124 나라의 숫자
HAS3ONG
2018. 11. 18. 16:47
출처
https://programmers.co.kr/learn/courses/30/lessons/12899
소스
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 | #include <string> #include <vector> using namespace std; string solution(int n) { string arr[3] = {"4","1","2"}; string answer = ""; int index; while(n>0) { index = n % 3; if(index == 0) { n = n-1; } n = n / 3; answer = arr[index] + answer; } return answer; } | cs |