前两个规则重写一下比较器就行
对于规则三,我先不管它,进行排序后与排序前的相对照输出
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
char[] t = in.nextLine().toCharArray();
Character[] ch = new Character[t.length];
for(int i = 0; i < t.length; i++)
ch[i] = t[i];
Arrays.sort(ch,(o1,o2) -> {
if(o1 >= 'a' && o1 <= 'z')
o1 = (char)(o1 - 'a' + 'A');
if(o2 >= 'a' && o2 <= 'z')
o2 = (char)(o2 - 'a' + 'A');
return o1 - o2;
});
int j = 0;
for(int i = 0; i < t.length; i++) {
if(t[i] < 'A' || (t[i] > 'Z' && t[i] < 'a') || t[i] > 'z'){
System.out.print(t[i]);
continue;
}
while(ch[j] < 'A' || (ch[j] > 'Z' && ch[j] < 'a') || ch[j] > 'z') j++;
System.out.print(ch[j ++]);
}
}
}