본문 바로가기
Problem-solving/프로그래머스

프로그래머스 - 자연수 뒤집어 배열로 만들기 (C++)

by taehee.kim.dev 2020. 3. 12.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
vector<int> solution(long long n) {
    vector<int> answer;
 
    string numbers_str = to_string(n);
 
    for(int i = 0; i < numbers_str.length(); i++){
        answer.push_back(numbers_str[i] - '0');
    }
 
    reverse(answer.begin(), answer.end());
 
    return answer;
}
cs

댓글