"프로그래머스 12932 자연수 뒤집어 배열로 만들기"의 두 판 사이의 차이

 
20번째 줄: 20번째 줄:
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='cpp'>
<syntaxhighlight lang='cpp'>
#include <string>
#include <vector>
using namespace std;
vector<int> solution(long long n) {
vector<int> solution(long long n) {
     vector<int> answer;
     vector<int> answer;

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;
}
#include <string>
#include <vector>

using namespace std;

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 }}