题解 | #图片整理#
图片整理
http://www.nowcoder.com/practice/2de4127fda5e46858aa85d254af43941
import java.util.Scanner; import java.util.Arrays;
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()) { String str = sc.nextLine(); char[] strs = str.toCharArray();
// Arrays.sort(strs); Main.sort(strs);
System.out.println(strs);
}
}
//Shell sort for improve this speed, but not like what I thought
public static void sort(char[] arr) {
int j;
for (int gap = arr.length / 2; gap > 0; gap /= 2) {
for (int i = gap; i < arr.length; i++) {
char tmp = arr[i];
for (j = i; j >= gap && tmp < arr[j - gap]; j -= gap) {
arr[j] = arr[j - gap];
}
arr[j] = tmp;
}
}
}
}