https://programmers.co.kr/learn/courses/30/lessons/42883
#include <string>
#include <vector>
using namespace std;
string solution(string number, int k) {
string answer = "";
int size = number.size();
int offset = 0;
int count = size - k;
for(int j=0;j<size - k;j++){
int maxN = 0;
int maxIdx = offset;
for(int i=offset;i<= size-count;i++){
if(maxN < number.at(i) -'0'){
maxIdx = i;
maxN = number.at(i)-'0';
}
}
if(maxIdx+count == size){// 나머지 볼거 없음
return answer + number.substr(maxIdx, count);
}
answer += to_string(maxN);
count--;
offset = maxIdx+1;
}
return answer;
}
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string solution(string number, int k) {
string answer = "";
answer = number.substr(k);
for(int i = k-1;i >=0;i--){
int j = 0;
do{
if(number[i] >= answer[j]){
char temp = answer[j];
answer[j] = number[i];
number[i] = temp;
j++;
}else{
break;
}
}while(1);
}
return answer;
}