题目有点绕,一个是要二分,用三个字符串,存前,中,后三个,前,后部分都降序排序,然后后半部分再反转一下,讲三部分合起来就好了。
import java.util.Scanner;
public class dividesort {
public static void sort(StringBuffer s){
for(int i=0;i<s.length();i++){
for(int j=i;j<s.length();j++){
if(s.charAt(i)>s.charAt(j)){
char tmp=s.charAt(i);
s.setCharAt(i,s.charAt(j));
s.setCharAt(j, tmp);
}
}
}
}
public static void main(String args[]){
Scanner in=new Scanner(System.in);
String s=new String(in.nextLine());
StringBuffer s1=new StringBuffer(s.substring(0, s.length()/2));
StringBuffer s2=new StringBuffer();
StringBuffer s3=new StringBuffer();
if(s.length()%2==0){
s2.append(s.substring(s.length()/2,s.length()));
}
else{
s2.append(s.substring((s.length()+1)/2, s.length()));
s3.append(s.substring(s.length()/2,(s.length()+1)/2));
}
sort(s1);
sort(s2);
s2.reverse();
StringBuffer res=new StringBuffer(s1.append(s3.append(s2)));
System.out.println(res);
}
}