Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 234 ms):
import java.io.*;
import java.util.*;

public class D_Digital_string_maximization {
    public static void main(String[] args) throws IOException {
        FastIO io = new FastIO();
        int t = io.nextInt();
        while(t-- > 0) {
            String s = io.next();
            int n = s.length();
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = (int)(s.charAt(i) - '0');
            for (int i = 0; i < n - 1; i++) {
                boolean curr = true;
                for (int j = 0; j < n - i - 1; j++) {
                    if (a[j]+1 < a[j + 1]) {
                        int temp = a[j];
                        a[j] = a[j + 1]-1;
                        a[j + 1] = temp;
                        curr = false;
                    }
                }
                if(curr) break;
            }
            StringBuilder res = new StringBuilder();
            for(int i: a) res.append(i);
            io.println(res);
        }
        io.close();
    }
    
    static class FastIO {
        BufferedReader br;
        PrintWriter pw;
        StringTokenizer st;

        public FastIO() {
            br = new BufferedReader(new InputStreamReader(System.in));
            pw = new PrintWriter(new BufferedOutputStream(System.out));
        }

        public FastIO(String inputFile, String outputFile) throws IOException {
            br = new BufferedReader(new FileReader(inputFile));
            pw = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        void print(Object obj) {
            pw.print(obj);
        }

        void println(Object obj) {
            pw.println(obj);
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            pw.close();
        }
    }
}


Solution 2 (runtime: 296 ms):
import java.util.*;



public class Main {

public static void main(String []args) {

Scanner sc=new Scanner(System.in);

int t=sc.nextInt();

while(t-->0){

String s = sc.next();

char[] arr = s.toCharArray();



for (int i = 0; i < arr.length; i++) {

int best = arr[i] - '0', pos = i;



for (int j = i; j < Math.min(i + 10, arr.length); j++) {

if ((arr[j] - '0') - (j - i) > best) {

best = (arr[j] - '0') - (j - i);

pos = j;

}

}



while (pos > i) {

char temp = arr[pos];

arr[pos] = arr[pos - 1];

arr[pos - 1] = temp;

pos--;

}



arr[i] = (char) (best + '0');

}



System.out.println(new String(arr));

}

}

}