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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vi = vector<int>;
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
using vpi = vector<pair<int,int>>;
using vppi = vector<pair<int,int>,int>;
using pi = pair<int, int>;
using ppi = pair<pair<int,int>,int>;
#define endl "\n"
#define INF 1e18
#define ll long long 
#define pl pair<long long, long long>
#define vvi vector<vector<int>>
const int MOD = 1e9 + 7;

struct mi {
    int v;
    explicit operator int() const { return v; }
    mi() { v = 0; }
    mi(long long _v) : v(_v % MOD) { v += (v < 0) * MOD; }
};
mi &operator+=(mi &a, mi b) {
    if ((a.v += b.v) >= MOD) a.v -= MOD;
    return a;
}
mi &operator-=(mi &a, mi b) {
    if ((a.v -= b.v) < 0) a.v += MOD;
    return a;
}
mi operator+(mi a, mi b) { return a += b; }
mi operator-(mi a, mi b) { return a -= b; }
mi operator*(mi a, mi b) { return mi((long long)a.v * b.v); }
mi &operator*=(mi &a, mi b) { return a = a * b; }
mi pow(mi a, long long p) {
    assert(p >= 0);
    return p == 0 ? 1 : pow(a * a, p / 2) * (p & 1 ? a : 1);
}
mi inv(mi a) {
    assert(a.v != 0);
    return pow(a, MOD - 2);
}
mi operator/(mi a, mi b) { return a * inv(b); }
// //---------------------------------Debugging------------------------------------------------------------------------------------------------------//
#define dbg(v) for(auto &x : v) { cout << x << " "; } cout << endl;
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T> ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T> ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T> ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T> ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
long long binpow(long long a, long long b) {long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; }
long long binpowm(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; }
//---------------------------------------------------------------------------------------------------------------------------------------------------//



void solve() {
string s;cin>>s;
vi temp;
vector<bool>check(s.length(),true);
for(int i= 0 ;i<s.length();++i)
{
    int mx = (int)(s[i] - '0');
    // cout<<mx<<" "; 
    int k =0 ;
    int j = i;
    int pos = i;
while(k <= 9 && j<s.length())
{
int val = (int)(s[j] - '0') - k;
if(val > mx)
{
    mx = val;
    pos = j;   
}
++j; ++k;
}
temp.pb(mx);
for(int j = pos;j>i;--j)
{
    swap(s[j],s[j-1]);
}
}
for(auto &x : temp)
{
    cout<<x;
}
cout<<endl;
}

    signed main() {  
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
        #endif
    // cin.ignore();
        int test = 1;
        cin >> test;
        while (test--) {
            solve();
        }

        return 0;
    }

Solution 2 (runtime: 78 ms):
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	int T,len,x;
	cin>>T;
	while(T--) {
		cin>>s;
		len=s.size();
		x=len;
	
			for(int i=1; i<len; i++) {
				if(s[i]==0)continue;
				int j=i; 
				while(s[j]>s[j-1]+1) {
					if(s[j]==0)break;
					s[j]-=1;
					swap(s[j],s[j-1]);
					j--;
					if(j==0)break;
				}
			}
		
		cout<<s<<endl;
	}
	return 0;
}