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

Code 1:
/*************************************************************************************
أَعُوذُ بِاللَّهِ مِنَ الشَّيْطَانِ الرَّجِيمِ
بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ
الرَّحْمَنِ الرَّحِيمِ
مَالِكِ يَوْمِ الدِّينِ
إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ
اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ
صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ
 
->  In the name of Allah, the Most Gracious, the Most Merciful.
->  Praise be to Allah, the Lord of all the worlds.
->  The Most Gracious, the Most Merciful.
->  Master of the Day of Judgment.
->  You alone we worship, and You alone we ask for help.
->  Guide us on the Straight Path,
->  the path of those who have received Your grace; 
->  not the path of those who have brought down wrath upon themselves,
->  nor of those who have gone astray. (AAMEEN)
 
**************************************************************************************/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main (){
    ll t;cin>>t;while(t--){
        string s,s1;cin>>s;
      ll count1=0,count0=0;
      s1.push_back(s[0]);
      for(ll i=1;i<s.size();i++){
        if(s[i]=='1')count1++;
        else if(s[i]=='0')count0++;
        else{
          ll x=(s[i]-'0')-(count1+count0);
          s1=s1+(to_string(x));
        }
      }
      for(ll i=1;i<s.size();i++){
        if(s[i]=='0'||s[i]=='1')s1.push_back(s[i]);
      }
      
      string s3=s1;
      ll cnt=s1.size();
      for(ll i=1;i<=9;i++){
        for(ll j=0;j<cnt-1;j++){
            if((s1[j]-'0')<((s1[j+1]-'0')-1)){
                ll x=(s1[j+1]-'0')-1;
                 char ch = to_string(x)[0];
                s1[j+1] = ch;
                char c=s1[j];
                 s1[j]=s1[j+1];
                 s1[j+1]=c;
               // swap(s1[j],s1[j+1]);
                
                
            }
        }
        if(s3==s1)break;
        s3=s1;
      }
      cout<<s1<<endl;
    }
    return 0;
}

Code 2:
/*************************************************************************************
أَعُوذُ بِاللَّهِ مِنَ الشَّيْطَانِ الرَّجِيمِ
بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ
الرَّحْمَنِ الرَّحِيمِ
مَالِكِ يَوْمِ الدِّينِ
إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ
اهْدِنَا الصِّرَاطَ الْمُسْتَقِيمَ
صِرَاطَ الَّذِينَ أَنْعَمْتَ عَلَيْهِمْ غَيْرِ الْمَغْضُوبِ عَلَيْهِمْ وَلَا الضَّالِّينَ
 
->  In the name of Allah, the Most Gracious, the Most Merciful.
->  Praise be to Allah, the Lord of all the worlds.
->  The Most Gracious, the Most Merciful.
->  Master of the Day of Judgment.
->  You alone we worship, and You alone we ask for help.
->  Guide us on the Straight Path,
->  the path of those who have received Your grace; 
->  not the path of those who have brought down wrath upon themselves,
->  nor of those who have gone astray. (AAMEEN)
 
**************************************************************************************/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main (){
    ll t;cin>>t;while(t--){
        string s,s1;cin>>s1;
      // ll count1=0,count0=0;
      // s1.push_back(s[0]);
      // for(ll i=1;i<s.size();i++){
      //   if(s[i]=='1')count1++;
      //   else if(s[i]=='0')count0++;
      //   else{
      //     ll x=(s[i]-'0')-(count1+count0);
      //     s1=s1+(to_string(x));
      //   }
      // }
      // for(ll i=1;i<s.size();i++){
      //   if(s[i]=='0'||s[i]=='1')s1.push_back(s[i]);
      // }
      
      string s3=s1;
      ll cnt=s1.size();
      for(ll i=1;i<=9;i++){
        for(ll j=0;j<cnt-1;j++){
            if((s1[j]-'0')<((s1[j+1]-'0')-1)){
                ll x=(s1[j+1]-'0')-1;
                 char ch = to_string(x)[0];
                s1[j+1] = ch;
                char c=s1[j];
                 s1[j]=s1[j+1];
                 s1[j+1]=c;
               // swap(s1[j],s1[j+1]);
                
                
            }
        }
        if(s3==s1)break;
        s3=s1;
      }
      cout<<s1<<endl;
    }
    return 0;
}

Answer: 2