문자열로 변경해주고, 받은 문자열을 내림차순으로 정렬 후
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 |