시간 복잡도 을 허용하므로 정렬을 이용하여 문제를 해결할 수 있습니다.
선택 정렬을 이용해 문제를 해결해보겠습니다`
문자열로 입력받아 각 문자를 숫자로 변환해 벡터로 저장한 뒤 정렬을 수행하면 됩니다.
// boj s5 1427
// 소트인사이드
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string input;
cin >> input;
vector<int> v(input.length(), 0);
for (int i = 0; i < input.length(); i++)
{
v[i] = stoi(input.substr(i, 1));
}
for (int i = 0; i < v.size(); i++)
{
int max = i;
for (int j = i+1; j < v.size(); j++)
{
if (v[j] > v[max])
max = j;
}
::swap(v[i], v[max]);
}
for (int i = 0; i < v.size(); i++)
cout << v[i];
return 0;
}