Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define vstr vector<string>
#define str string
#define f(i, n) for (long long i = 0; i < n; i++)
#define fi(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define YES cout << "YES"<<'\n'
#define NO cout << "NO"<<'\n'
#define Yes cout << "Yes"<<'\n'
#define No cout << "No"<<'\n'
#define vpll vector<pair<ll,ll>>
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define fr2(i,a,b) for(ll i=a;i>=b;i--)
#define F first
#define S second
int mod = 1e9+7;
using namespace std;

void bankai()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
}
ll gcd(ll a, ll b)
{
    if (b == 0)return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return (a / gcd(a, b) * b);
}
bool prime(ll n)
{
    if (n <= 1)return false;
    if (n <= 3)return true;
    if (n % 2 == 0)return false;
    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)return false;
    }
    return true;
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second > b.second);
}
bool is_palindrome(str s)
{
    ll mid = s.size()/2;
    ll n = s.size();
    f(i, mid)
    {
        if(s[i] != s[n - i - 1])return false;
    }
    return true;
}
long long calculateFactorial(ll n)
{
    if (n == 0 || n == 1)
    {
        return 1;
    }
    return n * calculateFactorial(n - 1);
}
ll Digit_Sum(int a)
{
    int sum = 0;
    for (int i = a; i > 0; i /= 10)
    {
        sum += i % 10;
    }
    return sum;
}
int nth_sqr_func(ll mid, ll n)
{
    ll ans = 1;
    while(n>0)
    {
        ans=ans*mid;
        n--;
    }
    return ans;
}
set<ll>s;
int NOD(int n)
{
    for(ll i = 1 ; i <= sqrt(n) ; i++)
    {
        if(n%i==0)
        {
            ll x = i;
            ll y = n/i;
            s.insert(x);
            s.insert(y);
        }
    }
}
ll ans = 0;
void prime_fact(ll n)
{
    ans = 0;
    for(ll i = 2 ; i*i <= n ; i++)
    {
        if(n%i==0)
        {
            ans++;
            //ll cnt = 0;
            while(n%i==0)
            {
                //cnt++;
                n/=i;
            }

            //cout << i << " ";//<< "^" << cnt << " ";
        }

    }
    if(n>1)ans++;
    cout << ans << '\n';
    // else cout << '\n';
}


//-------------------------------------------------//
//               main code here                    //
//-------------------------------------------------//


void solve()
{
    str s;
    cin >> s;
    int n = s.size();

    for (int i = 1; i < n; ++i)
    {
        for (int j = i; j > 0 && s[j] - s[j - 1] > 1; --j)
        {
            s[j]--;
            swap(s[j], s[j - 1]);
        }
    }

    cout << s << '\n';
}




int main()
{
    bankai();

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
//4 7
//1 2 5 9

//6
//  92 82 21 16 18 95




Solution 2 (runtime: 92 ms):
#include <bits/stdc++.h>

using namespace std;



template <typename A, typename B>

ostream &operator<<(ostream &os, const pair<A, B> &p) {

    return os << '(' << p.first << ", " << p.second << ')';

}



template <typename T_container, typename T = typename enable_if<

                                    !is_same<T_container, string>::value,

                                    typename T_container::value_type>::type>

ostream &operator<<(ostream &os, const T_container &v) {

    os << '{';

    string sep;

    for (const T &x : v)

        os << sep << x, sep = ", ";

    return os << '}';

}



void dbg_out() { cerr << endl; }



template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {

    cerr << ' ' << H;

    dbg_out(T...);

}



#ifdef LOCAL

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)

#else

#define debug(...)

#endif



int main() {

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int T;

    cin >> T;

    while (T--) {

        string S;

        cin >> S;

        int N = int(S.size());

        for (int i = 0; i < N; i++) {

            int mxDiff = S[i] - '0', k = i;

            for (int j = i; j < min(i + 10, N); j++) {

                if (S[j] - '0' - (j - i) > mxDiff) {

                    mxDiff = S[j] - '0' - (j - i);

                    k = j;

                }

            }

            while (k > i) {

                swap(S[k], S[k - 1]);

                k--;

            }

            S[i] = (char) (mxDiff + '0');

        }

        cout << S << '\n';

    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed =

        std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    cerr << "time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

}