Algorithm/C++ - 프로그래머스

프로그래머스 - 정수 내림차순으로 배치하기 C++

ㅇㅇ잉 2021. 2. 14. 04:44

문자열로 변경해주고, 받은 문자열을 내림차순으로 정렬 후

stoll함수로 ll type으로 변환해주면 된다!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
long long solution(long long n) {
    string s = to_string(n);
    
    sort(s.rbegin(),s.rend());
    
    long long answer = stoll(s);
    return answer;
}
cs