每次都是和离当前数字最近,且交换到当前位置后的数字比任何一个可以交换到当前位置的数字大的那个数字交换。会超时所以要想到距离超过9了就是负数了后面就没必要遍例了

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int t;

int main(){
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++){
            int a=s[i]-'0';
            int ma=0;
            int biao=0;
            int b;
            int shu=0;
            for(int j=i+1;j<s.size();j++){
                b=s[j]-'0';
                if(shu>=9)break;
                shu++;
                if((b-j+i)>a&&(b-j+i)>ma){
                    ma=b-j+i;
                    biao=j;
                }
                
            }
            if(biao!=0){
                char bb=s[biao];
                
                for(int z=biao;z>=i+1;z--){
                    s[z]=s[z-1];
                }
                s[i]=bb-biao+i; 
            }
        }
        cout<<s<<'\n';
    }
	return 0;
} 

}