프로그래머스 - 124 나라의 숫자

2022. 9. 17. 14:00코딩 공부 연습

반응형

규칙을 찾으면 쉬운데 안떠올라서 오래걸렸다 흑흑!

#include <string>
#include <vector>
#include <iostream>

using namespace std;

int otf[3] = {4,1,2};
string solution(int n) {
    string answer = "";
    vector <int> arr;
    int tmp;
    while(n > 0)
    {
        int tmp = n%3;
        if (tmp == 0)
            n--;
        arr.push_back(otf[tmp]);
        n/=3;
    }
    for(int i = arr.size()-1; i>=0; i--)
        answer = answer + to_string(arr[i]);s
    return answer;
}

16602등!