publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); for (; in.hasNext();) { String s = in.nextLine(); int n = s.length(); boolean[] st = newboolean[n]; Arrays.fill(st, false); List<Entity> list = new ArrayList<>(); for (int i = 0; i < n; i++) { char c = s.charAt(i); if (!Character.isAlphabetic(c)) { st[i] = true; } else { int ascii = Character.isUpperCase(c) ? c + 32 : c; Entity ent = new Entity(c, ascii, i); list.add(ent); } } Collections.sort(list, new Comparator<Entity>(){ @Override publicintcompare(Entity a, Entity b){ if (a.ascii != b.ascii) return a.ascii - b.ascii; elsereturn a.idx - b.idx; } }); StringBuilder res = new StringBuilder(); for (int i = 0, j = 0; i < n && j < n;) { for (; i < n && st[i]; ++i) res.append(s.charAt(i)); for (; i < n && j < n && !st[i]; ++i, ++j) res.append(list.get(j).c); } System.out.println(res.toString()); } } }
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); for (; in.hasNext();) { String s = in.nextLine(); int n = s.length(); List<Character> alpha = new ArrayList<>(); for (int i = 65; i < 91; i++) { for (int j = 0; j < n; j++) { char c = s.charAt(j); if (c == i || c == i + 32) { alpha.add(c); } } } StringBuilder res = new StringBuilder(); for (int i = 0, j = 0, len = alpha.size(); i < n; i++) { if (!Character.isAlphabetic(s.charAt(i))) res.append(s.charAt(i)); else res.append(alpha.get(j++)); } System.out.println(res.toString()); } } }