import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 String line = in.nextLine(); PriorityQueue<int[]> pq = new PriorityQueue<>( (o1, o2) -> { char c1 = Character.toLowerCase((char)o1[0]); char c2 = Character.toLowerCase((char)o2[0]); if (c1 == c2) { return o1[1] - o2[1]; //如果一样则比较所在位置 } else { return c1 - c2; //如果不一样则比较字符 } } ); for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { pq.add(new int[] {c, i}); } } for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) { //不是字母 System.out.print(c); } else { //是字母 System.out.print((char)pq.poll()[0]); } } } }