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

Solution 1 (runtime: 62 ms):
//Practice and Patience is the way to CP


#include <bits/stdc++.h>
using namespace std;
#define mod (int) 998244353
#define MOD (int) 1e9+7
// Big two primes
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define vii vector<ii>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)
const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}
void pr(int x) {cout << x;}
void prl(int x) {cout << x << endl;}
// typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;
//bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x) { int lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) {int mid = (lo + hi) / 2; if (mid * mid * mid < x) {lo = mid;} else hi = mid;} if (hi * hi * hi <= x) return hi; else return lo;}
const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(1 * 1e6 + 10);

void solve() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0';
        int pos = i;
        for (int j = i; j < min(i + 10, s.size()); j++) {
            if ((s[j] - '0' - (j - i)) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = best + '0';
    }
    cout << s << endl;

}
signed main() {
    fio;
    //srand(time(NULL));
    int T = 1;
    cin >> T;

    while (T--) {
        solve();
    }
}

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

using namespace std;







int main() {

    int t;

    cin >> t;



    while (t--) {

    string s;

    cin>>s;



        

        for(int i=s.size()-1;i>=1;i--)

        {

           if(s[i]-s[i-1]>1)

           {

            int last=s.size();

            char c=s[i-1];

            for(int j=i;j<last;j++)

            {

                if(s[j]<=c+1)

                {

                    last=j;

                }

            }

            last--;

            for(int j=i-1;j<last;j++)

            {

                s[j]=s[j+1]-1;

            }

            s[last]=c;

            



           }

        }



        cout<<s<<endl;

    





    }

    return 0;

}