ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: python

Code 1:
def recursive(a,begin):
    if begin==len(a):
        return
    max_val = a[begin]
    max_index = begin
    for i in range(begin, min(len(a), begin+8)):
        if max_val<(a[i] - (i-begin)):
            max_val= a[i]-i+begin
            max_index = i
    while max_index !=begin:
        a[max_index], a[max_index-1] = a[max_index-1],a[max_index]-1
        max_index-=1
def solve():
    n = input()
    a = list(map(int,n))
    begin = 0
    while begin<len(a):
        recursive(a,begin)
        begin+=1
    for i in a:
        print(i,end='')
    print('\n')
x = int(input())
for i in range(x):
    solve()

Code 2:
def recursive(a,begin):
    if begin==len(a):
        return
    max_val = a[begin]
    max_index = begin
    for i in range(begin, min(len(a), begin+9)):
        if max_val<(a[i] - (i-begin)):
            max_val= a[i]-i+begin
            max_index = i
    while max_index !=begin:
        a[max_index], a[max_index-1] = a[max_index-1],a[max_index]-1
        max_index-=1
def solve():
    n = input()
    a = list(map(int,n))
    begin = 0
    while begin<len(a):
        recursive(a,begin)
        begin+=1
    print(''.join(map(str, a)))
x = int(input())
for i in range(x):
    solve()

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define int long long int

void solve(){
	int n;

	string a;
	cin>> a;
	n = a.size();

	for (int i = 0; i < n; ++i)
	{
		
		int mx = a[i]-'0', mxi=i;

		for (int j = i+1; j < i+9 && j < n; ++j)
		{
			if(mx < (a[j]-'0'-(j-i))){
				mx = (a[j]-'0'-(j-i));

				mxi = j;
			}
		}

		// swap

		
		int c = a[i], cn = 0;
		for (int k = i+1; k <= mxi; ++k)
		{
			cn = a[k];
			a[k] = c;
			c = cn;
		}
		a[i] = mx+'0';

		// cerr<< a <<",";
	}

	// cerr<<endl;

	cout<< a << endl;
}

int32_t main(){

	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);
	// string s;
	// getline(cin, s);

	// int i = 0;
	// while(s[i] != '\0'){
	// 	cout<< s[i];
	// 	i++;
	// }

	// cout<< s << endl;

	int t = 0;

    cin>> t;
    while(t--){
    	solve();
    }

    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

void solve(){
	int n;

	string a;
	cin>> a;
	n = a.size();

	for (int i = 0; i < n; ++i)
	{
		
		int mx = a[i]-'0', mxi=i;

		for (int j = i+1; j < n; ++j)
		{
			if(mx < (a[j]-'0'-(j-i))){
				mx = (a[j]-'0'-(j-i));

				mxi = j;
			}
		}

		// swap

		
		int c = a[i], cn = 0;
		for (int k = i+1; k <= mxi; ++k)
		{
			cn = a[k];
			a[k] = c;
			c = cn;
		}
		a[i] = mx+'0';

		// cerr<< a <<",";
	}

	// cerr<<endl;

	cout<< a << endl;
}

int main(){
	// string s;
	// getline(cin, s);

	// int i = 0;
	// while(s[i] != '\0'){
	// 	cout<< s[i];
	// 	i++;
	// }

	// cout<< s << endl;

	int t = 0;

    cin>> t;
    while(t--){
    	solve();
    }

    return 0;
}

Answer: 1
Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    int t;

    cin>>t;

    while(t--){

  string s;

  cin>>s;

  ll n=s.size();

  ll i;

  vector<ll>v(n);

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

      v[i]=s[i]-'0';

  }

  for(i=0; i+9<n; i++ ){

      ll  m=LLONG_MIN;

      ll idx=-1;

      ll k=1;

      for(ll j=i+1; j<i+9; j++){

          if(v[j]-k > m){

              idx=j;

              m=v[j]-k;

          }

          k++;

      }

      if(m>v[i]){

          for(int y=idx; y>i; y--){

            v[y]=v[y-1];

          }

          v[i]=m;

      }

  }

   for(int l=i; l<n; l++){

      ll m=LLONG_MIN;

      ll idx=-1;

      ll k=1;

      for(ll j=l+1; j<n; j++){

          if(v[j]-k > m){

              idx=j;

              m=v[j]-k;

          }

          k++;

      }

     // cout<<m<<endl;

      if(m>v[l]){

          for(ll y=idx; y>l; y--){

            v[y]=v[y-1];

          }

          v[l]=m;

      }

//       for(auto it:v){

//       cout<<it;

//   }

//   cout<<endl;

  }

  for(auto it:v){

      cout<<it;

  }

  cout<<endl;

  

    }

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

  string s;

  cin>>s;

  int n=s.size();

  int i;

  vector<int>v(n);

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

      v[i]=s[i]-'0';

  }

  for(i=0; i+9<n; i++ ){

      int m=INT_MIN;

      int idx=-1;

      int k=1;

      for(int j=i+1; j<i+9; j++){

          if(v[j]-k > m){

              idx=j;

              m=v[j]-k;

          }

          k++;

      }

      if(m>v[i]){

          int z=1;

          for(int k=idx; k>i; k--){

              v[k]=v[k]-z;

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

              z++;

          }

      }

  }

   for(int l=i; l<n; l++){

      int m=INT_MIN;

      int idx=-1;

      int k=1;

      for(int j=l+1; j<n; j++){

          if(v[j]-k > m){

              idx=j;

              m=v[j]-k;

          }

          k++;

      }

     // cout<<m<<endl;

      if(m>v[l]){

          for(int y=idx; y>l; y--){

            v[y]=v[y-1];

          }

          v[l]=m;

      }

//       for(auto it:v){

//       cout<<it;

//   }

//   cout<<endl;

  }

  for(auto it:v){

      cout<<it;

  }

  cout<<endl;

  

    }

}

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

Code 1:
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    int t;
    cin >> t;

    while (t--) {
        
        string s;
        cin >> s;
        ll n = s.size();
        for (ll i = 0; i < n; i++) {
            ll maxc = s[i] - '0';
            ll maxi = i;
            for (ll j = i ; j < min(i+10,n); j++) {
                if (s[j] - '0' + (i - j) > maxc) {
                    maxc = s[j] - '0' + (i - j);
                    maxi = j;
                }
            }ll k = maxi;

            while(maxi > i) {
                swap(s[maxi], s[maxi - 1]);
                maxi--;
            }
            s[i] += (i - k);
        }

        cout <<s << endl;
    }

    return 0;
}


Code 2:
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    int t;
    cin >> t;

    while (t--) {
        
        string s;
        cin >> s;
        ll n = s.size();
        for (int i = 0; i < n; i++) {
            ll maxc = s[i] - '0';
            ll maxi = i;
            for (int j = i + 1; j < n; j++) {
                if (s[j] - '0' + (i - j) > maxc) {
                    maxc = s[j] - '0' + (i - j);
                    maxi = j;
                }
            }

            swap(s[i], s[maxi]);
            s[i]+= (i - maxi);
        }

        cout << s << endl;
    }

    return 0;
}


Answer: 1
Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		vector<int> a;
		if(s.length() < 9){
			for(int i=0; i<s.length(); i++){
				a.push_back(s[i]-'0');
			}
		}
		else{
			for(int i=0; i<s.length(); i++){
				a.push_back(s[i]-'0');
			}
		}
	//	vector<int> a = {9, 8, 7, 6, 5, 4 ,3, 2, 1};
		vector<int> result;
		int size = a.size();
		for(int j=0; j<size; j++){
			int max = a[0];
			int track = 0;
			for(int i=0; i<a.size(); i++){
				if(max < a[i] - i){
					max = a[i] - i;
					track = i;
				}
			}
			result.push_back(max);
			a.erase(a.begin() + track);

		}
		for(int i=0; i<result.size(); i++){
			cout<<result[i];
		}
		if(s.length() > 9){
			for(int i=10; i<s.length(); i++){
				cout<<s[i];
			}
		}
		cout<<endl;	
	}
	
}

Code 2:
#include<iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		for(int i=0; i<s.length(); i++){
			if(s[i] < s[i+1]-1){
				swap(s[i], s[i+1]);
				s[i]--;
				if(i>=1){
					i-=2;
				}
			}
		}
		cout<<s<<endl;
	}
}

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <iostream>
#include <algorithm>
#include <limits>
#include <map>
#include <set>
#include <vector>
#define vi vector<int>
#define pb push_back
#define int long long
using namespace std;
const int N = 5e5+10; 
int t,sum=0;
string s;

void solve(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		for(int j=i;j>=1;j--){
			if(s[j-1]<s[j]-1){
				s[j]=(s[j]-'0')-1+'0';
				char w=s[j];
				s[j]=s[j-1];
				s[j-1]=w;
			}
		}
	} 
	cout<<s<<endl;
}

signed main(void){
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	solve();
	return 0;
} 

Code 2:
#include <iostream>
#include <algorithm>
#include <limits>
#include <map>
#include <set>
#include <vector>
#define vi vector<int>
#define pb push_back
#define int long long
using namespace std;
const int N = 5e5+10; 
int t,sum=0;
string s;

void solve(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		for(int j=i;j>=1;j--){
			if(s[j-1]<s[j]-1){
				s[j]=(s[j]-'0')-1+'0';
				char w=s[j];
				s[j]=s[j-1];
				s[j-1]=w;
			}
			else{
				break;
			}
		}
	} 
	cout<<s<<endl;
}

signed main(void){
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	solve();
	return 0;
} 

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
#include "bits/stdc++.h"

#define int long long

using namespace std;

void A()

{

	string s;

	cin >>s;

	map<int,int> mp;

	int n=s.size(),i,j;

	int d=0;

	for(int p=1;p<=50000;p++)

	{

	for(j=n-1,i=n-1;i>0;i--)

	{

		j=i;

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

		{

			char q;

			q=s[i]-1;

			s[i]=s[i-1];

			s[i-1]=q;

		}

	}

	}

	cout <<s<<endl;

	

}

signed main()

{

	int t;

	cin >>t;

	while(t--) A();

	return 0;

	

}

Code 2:
#include "bits/stdc++.h"

#define int long long

using namespace std;

void A()

{

	string s;

	cin >>s;

	map<int,int> mp;

	int n=s.size(),i,j;

	int d=0;

	for(int p=1;p<=25000;p++)

	{

	for(j=n-1,i=n-1;i>0;i--)

	{

		j=i;

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

		{

			char q;

			q=s[i]-1;

			s[i]=s[i-1];

			s[i-1]=q;

		}

	}

	}

	cout <<s<<endl;

	

}

signed main()

{

	int t;

	cin >>t;

	while(t--) A();

	return 0;

	

}

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    vector<string> answers;
    while(t--){
        string s;
        cin >> s;
        int n=s.size();
        vector<int> newvalues;
        for(int i =0;i<n-1; i++){
            newvalues.clear();
            for(int m=0; m<n; m++){
            newvalues.push_back((s[m]-'0')-m+i);
            }

            int max=0;
            int toswapindex=0;
            for(int j=i+1;j<n;j++){
                if(s[i]-'0'<newvalues[j]){
                    int cur = newvalues[j];
                    if(cur>max){
                        max=cur;
                        toswapindex=j;
                    }
                }
            }
            if(max!=0){
                for(int k=toswapindex; k>i;k--){
                    s[k]=s[k-1];
                }
                s[i]= max+'0';
            }
        }
        answers.push_back(s);
    }
    for(string answer : answers){
        cout << answer << "\n";
    }
    return 0;
}

Code 2:
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int main(){
    int t;
    cin >> t;
    vector<string> answers;
    while(t--){
        string s;
        cin >> s;
        int n=s.size();
        vector<long long> newvalues;
        for(int i =0;i<n-1; i++){
            newvalues.clear();
            
            for(int m=i; m<min(i + 10, n); m++){
            newvalues.push_back((s[m]-'0')-m+i);
            }

            int max=0;
            int toswapindex=0;
            for(int j=i+1;j<min(i + 10, n);j++){
                if(s[i]-'0'<newvalues[j-i]){
                    int cur = newvalues[j-i];
                    if(cur>max){
                        max=cur;
                        toswapindex=j;
                    }
                }
            }
            if(max!=0){
                for(int k=toswapindex; k>i;k--){
                    s[k]=s[k-1];
                }
                s[i]= max+'0';
            }
        }
        answers.push_back(s);
    }
    for(string answer : answers){
        cout << answer << "\n";
    }
    return 0;
}

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

Code 1:
#include <iostream>

using namespace std;



bool check(string a)

{

	for (int i = 0; i < a.size() - 1; ++i)

	{

		if (a[i + 1] == '0')

		{

			continue;

		}

		if (a[i] + 1 < a[i + 1])

		{

			return true;

		}

	}

	return false;

}



int main()

{

	int t;

	cin >> t;

	while (t--)

	{

		string s;

		cin >> s;

		while (check(s) == true)

		{

			for (int i = 0; i < s.size() - 1; ++i)

			{

				if (s[i] == '0')

				{

					continue;

				}

				if (s[i] + 1 < s[i + 1])

				{

					s[i + 1] -= 1;

					char temp = s[i];

					s[i] = s[i + 1];

					s[i + 1] = temp;

				}

			}

		}

		cout << s << endl;

	}

	

	return 0;

}

Code 2:
#include <iostream>

using namespace std;



bool check(string a)

{

	for (int i = 0; i < a.size() - 1; ++i)

	{

		if (a[i + 1] == '0')

		{

			continue;

		}

		if (a[i] + 1 < a[i + 1])

		{

			return true;

		}

	}

	return false;

}



int main()

{

	int t;

	cin >> t;

	while (t--)

	{

		string s;

		cin >> s;

		while (check(s) == true)

		{

			for (int i = 0; i < s.size() - 1; ++i)

			{

				if (s[i + 1] == '0')

				{

					continue;

				}

				if (s[i] + 1 < s[i + 1])

				{

					s[i + 1] -= 1;

					char temp = s[i];

					s[i] = s[i + 1];

					s[i + 1] = temp;

				}

			}

		}

		cout << s << endl;

	}

	

	return 0;

}

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

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N=1e5;



int32_t main() {

	ios::sync_with_stdio(0); 

	cin.tie(0);

	ll t;

	cin >> t;

	while (t--) {

		string s;

		cin>>s;

		ll n=s.size();

		for(ll i=0;i<s.size();i++){

			int in=0,idx=0;

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

				if(s[j]-j+i-'0'>in) {in=s[j]-j+i-'0'; idx=j;}

			}

			if(in!=s[i]-'0') {

				for(int j=idx-1;j>=i;j--){

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

				}

				s[i]=char(in+'0');

			}

		}

		cout<<s<<"\n";

	}	

    return 0;

}



Code 2:
#include <bits/stdc++.h>

using namespace std;



#define vi vector<int>

#define vvi vector<vector<int>>

#define vll vector<long long>

#define ll long long

#define all(n) n.begin(), n.end()

#define mod 1000000007



void solve(){

    string s; cin >> s;

    int n = s.size();



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

        int maxi = 0, ind = i;

        for(int j=i; j < min(i+9, n); j++){

            if(maxi < (s[j]-'0')+(i-j)){

                maxi = (s[j]-'0')+(i-j);

                ind = j;

            }

        }

        //cout << ind << " ";

        while(ind > i){

            swap(s[ind], s[ind-1]);

            ind--;

        }

        s[i] = '0'+maxi;

    }

    cout << s << endl;

}



int main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);



    int tt = (cin >> tt, tt);

    while(tt--) solve();

}



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

Code 1:
#include<bits/stdc++.h>



using namespace std;



#define rep(i, a, b) for (int i = a; i < (b); i++)

#define rrep(i, a, b) for (int i = a; i >= (b); i--)

#define range(i, a, b, s) for (int i = a; (s > 0 && i < (b)) || (s < 0 && i > (b)); i += s)

#define trav(a, x) for (auto& a : x)

#define all(x) begin(x), end(x)

#define sz(x) (int) (x).size()

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<pii> vpi;



template <typename T>

void print_arr(vector<T> a) {

	trav(x, a) cout << to_string(x) << " ";

	cout << "\n";

}



int T;

vi a;

string s;



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	cin >> T;

	while (T--) {

		cin >> s;



		vi skip(sz(s), 0);

		rep(i, 0, sz(s)) {

			if (skip[i]) continue;



			int mx = s[i] - '0';

			int mx_pos = i;

			int skipped = 0;

			rep(j, 1, 20) {

				if (i+j >= sz(s)) break;

				if (skip[i+j]) {

					skipped++;

					continue;

				}

				if (s[i+j] - '0' - j + skipped > mx) {

					//cout << i << " " << i+j << " " << s[i+j] - '0' - j << '\n';

					mx = s[i+j] -'0' - j + skipped;

					mx_pos = i+j;

				}

			}



			cout << mx;

			skip[mx_pos] = 1;

			i--;

		}



		cout << '\n';

	}



	return 0;

}



Code 2:
#include<bits/stdc++.h>



using namespace std;



#define rep(i, a, b) for (int i = a; i < (b); i++)

#define rrep(i, a, b) for (int i = a; i >= (b); i--)

#define range(i, a, b, s) for (int i = a; (s > 0 && i < (b)) || (s < 0 && i > (b)); i += s)

#define trav(a, x) for (auto& a : x)

#define all(x) begin(x), end(x)

#define sz(x) (int) (x).size()

typedef long long ll;

typedef pair<int, int> pii;

typedef vector<int> vi;

typedef vector<pii> vpi;



template <typename T>

void print_arr(vector<T> a) {

	trav(x, a) cout << to_string(x) << " ";

	cout << "\n";

}



int T;

vi a;

string s;



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);



	cin >> T;

	while (T--) {

		cin >> s;



		vi skip(sz(s), 0);

		rep(i, 0, sz(s)) {

			if (skip[i]) continue;



			int mx = s[i] - '0';

			int mx_pos = 0;

			rep(j, 1, 10) {

				if (i+j >= sz(s)) break;

				if (s[i+j] - '0' - j > mx) {

					//cout << i << " " << i+j << " " << s[i+j] - '0' - j << '\n';

					mx = s[i+j] -'0' - j;

					mx_pos = j;

				}

			}



			char prev = s[i];

			rep(j, 1, mx_pos+1) {

				if (i+j >= sz(s)) break;

				swap(s[i+j], prev);

			}



			s[i] = mx+'0';

		}

 

		cout << s << '\n';

	}



	return 0;

}



Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) 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] = char(best + '0');
    }
    cout << s<<endl;
}

int main() {
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) 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] = char(best + '0');
    }
    cout << s;
}

int main() {
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Answer: 1
Problem: 2050D - Digital string maximization
Language: c++23 

Code 1:
/**
 *    author:  tiansheng
 *    created: 2024.12.30 15:53:00 IST
 **/
#include <bits/stdc++.h>
#include "debug.h"
using namespace std;
#ifdef LOCAL
#include "debug.h"
#endif

void solve()
{
    string s;
    cin >> s;
    int i,j;
    for (int k = 0; k < s.length() + 1; k++)
    {
        if((s[k+1] - s[k]) > 1){
            i = k;j = k+1;
            do
            {
                s[j]--;
                // cout<<"s[j] "<<s[j]<<endl;
                swap(s[i],s[j]);
                i--;j--;
                // cout<<"cod "<<( i > 0 && j > 0 && ((s[j] - s[i]) > 1))<<endl;
            } while ( i >= 0 && j >= 0 && ((s[j] - s[i]) > 1));
            
        }
    }
    cout<<s<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

Code 2:
/**
 *    author:  tiansheng
 *    created: 2024.12.30 15:53:00 IST
 **/
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#endif

void solve()
{
    string s;
    cin >> s;
    int i, j;
    for (int k = 0; (k + 1) < s.length(); k++)
    {
        if ((s[k + 1] - s[k]) > 1)
        {
            i = k;
            j = k + 1;
            do
            {
                swap(s[i], --s[j]);
                i--; j--;
            } while (i >= 0 && j >= 0 && ((s[j] - s[i]) > 1));
        }
    }
    cout << s << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt;
    cin >> tt;
    while (tt--)
    {
        solve();
    }
    return 0;
}

Answer: 2
Problem: 2050D - Digital string maximization
Language: c++20 

Code 1:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		int k = i;
		for (int j = i; j < n && j < i + 10; j++)
		{
			if (s[j] - j > s[k] - k)
			{
				k = j;
			}
		}

		while (k > i)
		{
			s[k]--;
			swap(s[k - 1], s[k]);
			k--;
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

Code 2:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n-1; i++)
	{
		int cur = s[i] - '0';
		vector<int> steps(n, 0);
		int step = 1;
		int maxv = 0, maxind = -1;
		for (int j = i + 1; j < n && j < i+10; j++)
		{
			steps[j] = s[j] == '0' ? 0 : (s[j] - '0') - step;
			if (steps[j] > maxv && steps[j] > cur)
			{
				maxv = steps[j];
				maxind = j;
			}
			step++;
		}

		int j;
		for (j = (maxind == -1 ? -1 : maxind); j > i; j--)
		{
			swap(s[j], s[j - 1]);
		}

		if (j != -1)
		{
			int t = s[j] - '0';
			t = steps[maxind];
			s[j] = t + '0';
		}
	}

	cout << s << "\n";
}

int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}

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

Code 1:
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

int t,max1=numeric_limits<int>::min(),a;

char s[1000000];

int main(){

    scanf("%d",&t);

    while (t--)

    {

        a=0;

        scanf("%s",s);

        for (int i = 0; i < strlen(s); i++)

        {

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

            {

                if ((s[j]-'0')-j+i > max1)

                {

                    max1 = (s[j]-'0')-j+i;

                    a = j;

                }

                

            }

            for (int b = a; b > i; b--)

            {

                s[b] = s[b-1];

            }

                s[i] = '0';

            

            

            

            printf("%d",max1);

            max1=numeric_limits<int>::min();

        }

        printf("\n");

        

    }

    

    return 0;

}

Code 2:
#include <ostream>

#include <cstdio>

#include <algorithm>

#include<list>

#include<queue>

#include <iostream>

#include <cstring>

#include <math.h>

#include <cmath>

#include <string>

using namespace std;

using i64 = long long;

int T, n;

void solve() {

    string s; cin >> s;

    for (int i = 0; i < (int)s.size(); i ++) {

        int res = s[i], pos = i;

        for (int j = i + 1; j < min((int)s.size(), i + 11); j ++) 

            if ((int)s[j] - (j - i) > res) res = (int)s[j] - (j - i), pos = j;

        for (int j = pos; j > i; j --) swap(s[j], s[j - 1]), s[j - 1] --;

    }

    cout << s << '\n';

}

int main() {

    cin.tie(NULL) -> sync_with_stdio(false);

    cin >> T;

    while (T --) solve();

    return 0;

}

Answer: 2