프로그래머스 12932 자연수 뒤집어 배열로 만들기

Jmnote (토론 | 기여)님의 2024년 1월 2일 (화) 19:08 판

1 개요

프로그래머스 12932 자연수 뒤집어 배열로 만들기

2 C++

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(long long n) {
    string s = to_string(n);
    reverse(s.begin(), s.end());
    vector<int> answer;
    for(const auto& ch: s) {
        answer.push_back(ch-'0');
    }
    return answer;
}
vector<int> solution(long long n) {
    vector<int> answer;
    while(n != 0) {
        answer.push_back(n%10);
        n /= 10;
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}