那就打表呗。。。

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Map<Character,Character> map = new HashMap<>();
//  0    1    2   3     4     5   6    7   8     9   a    b    c    d     e   f
//0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
//  0    8   4    C   2    A     6    E   1    9    5    D    3    B     7    F
        map.put('1','8');
        map.put('2','4');
        map.put('3', 'C');
        map.put('4', '2');
        map.put('5', 'A');
        map.put('6', '6');
        map.put('7', 'E');
        map.put('8', '1');
        map.put('9', '9');
        map.put('a', '5');
        map.put('b', 'D');
        map.put('c', '3');
        map.put('d', 'B');
        map.put('e', '7');
        map.put('f', 'F');
        map.put('A','5');
        map.put('B','D');
        map.put('C','3');
        map.put('D','B');
        map.put('E','7');
        map.put('F','F');
        while (in.hasNext()) { 
           String str1 = in.nextLine();
           String[] strs = str1.split(" ");
           String str = strs[0]+strs[1];
           int len = str.length();
           int len1 = len/2;
           int len2 = len/2;
           if(len%2==1)len1++;
           char[] ch1 = new char[len1];
           char[] ch2 = new char[len2];
           for(int i=0;i<len;++i){
                if(i%2==0)
                    ch1[i/2] = str.charAt(i);
                else ch2[i/2] = str.charAt(i);
            }
            Arrays.sort(ch1);
            Arrays.sort(ch2);
            String res = "";
            String tempstr = "";
            for(int i =0;i<len;++i){
                if(i%2==0){
                    res+=map.get(ch1[i/2])==null?ch1[i/2]:map.get(ch1[i/2]);
                }
                else res+=map.get(ch2[i/2])==null?ch2[i/2]:map.get(ch2[i/2]);
            }
             
            System.out.println(res);
        }
    }
}