#include #include #include #include int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); enum check { CHECK, UNDECIDED, ENDED, }; char tmp; check check_f = UNDECIDED; std::vector input; while (std::cin >> tmp) { input.push_back(tmp-'0'); } std::vector part_input(input); while(check_f==UNDECIDED) { for (auto it = part_input.begin() + 1; it != part_input.end(); ++it) { if (part_input.front() < *it) { check_f = CHECK; break; } } if (check_f != CHECK) { part_input.erase(part_input.begin()); if (part_input.empty()) { check_f = ENDED; } } } //チェック std::vector max_checker(part_input); std::sort(max_checker.begin(), max_checker.end()); for (auto it = part_input.rbegin(); it != part_input.rend() && check_f != ENDED; ++it) { if (*it == max_checker.back()) { for (auto it2 = part_input.begin(); it2 != part_input.end(); ++it2) { if (*it2 != max_checker.back() || *it == *it2) { std::swap(*it, *it2); auto it3 = input.rbegin(); for (auto it4 = part_input.rbegin(); it4 != part_input.rend(); ++it4, ++it3) { *it3 = *it4; } check_f = ENDED; break; } } } } //出力 for (auto it : input) { std::cout << it; } std::cout << "\n"; return 0; }