정수 내림차순으로 배치하기

magicdrill·2024년 3월 5일
0

정수 내림차순으로 배치하기

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

long long solution(long long n) 
{
    long long answer = 0;
    int i;
    vector <int> temp;
    string s = to_string(n);
    string ans;
    
    for(i = 0; i < s.length(); i++)
    {
        temp.push_back(s[i]);    
    }
    sort(temp.begin(), temp.end(), greater<int>());
    for(i = 0; i < temp.size(); i++)
    {
        ans += temp[i];
    }
    answer = stoll(ans);
    
    return answer;
}

0개의 댓글