package com.syl.test.string;
import java.util.Scanner;
public class StringSort {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String in = sc.nextLine();
sc.close();
System.out.println(sort(in).replaceAll(",", " "));
}
public static String sort(String sin) {
boolean[] ifzimu = new boolean[sin.length()];
char[] ssin = sin.replaceAll(" ", ",").toCharArray();
char temp;
for (int i = 0; i < ssin.length; i++) {
if ((ssin[i] >= 'a' && ssin[i] <= 'z') || ssin[i] >= 'A'
&& ssin[i] <= 'Z') {
ifzimu[i] = true;
if (i > 0) {
// System.out.println("开始一个新的:");
for (int j = i; j >= 1; j--) {
// System.out.println("j:"+j+"ifzimu[j-1]"+ifzimu[j-1]+"ssin[j-1]:"+ssin[j-1]);
if (ifzimu[j - 1]
&& ((int) Character.toUpperCase(ssin[i]) < (int) Character
.toUpperCase(ssin[j - 1]))) {
temp = ssin[i];
ssin[i] = ssin[j - 1];
ssin[j - 1] = temp;
i = j - 1;
}
}
}
} else {
ifzimu[i] = false;
// System.out.println("i的值:"+i);
}
}
return String.valueOf(ssin);
}
}
字符串排序
最新推荐文章于 2023-04-14 17:49:04 发布