package com.patience.interview.huawei;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 字符串排序
* @author Green.Gee
* @date 2022/8/30 14:11
* @email green.gee.lu@gmail.com
*/
public class SortString {
/**
* input
* abc Ac
* output
* aAb cc
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
StringBuilder sb = new StringBuilder();
/**
* 加载字母
* 字母排序
* 原始元素和字母最终合并
*/
for(int i = 0; i < str.length(); i++){
char c = str.charAt(i);
if(Character.isLetter(c)){
sb.append(c);
}
}
char [] cs = sb.toString().toCharArray();
for(int i = 0;i < cs.length;i++){
for(int j = 0; j < cs.length - i - 1; j++){
if(Character.toLowerCase(cs[j]) - Character.toLowerCase(cs[j + 1]) > 0){
char temp = cs[j];
cs[j] = cs[j + 1];
cs[j + 1] = temp;
}
}
}
StringBuffer finalS = new StringBuffer();
int index = 0;
for(int i = 0; i < str.length(); i++){
char c = str.charAt(i);
if(Character.isLetter(c)){
finalS.append(cs[index++]);
}else{
finalS.append(c);
}
}
System.out.println(finalS.toString());
}
}
09-07
242
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-01
677
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-20
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-21
1572
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)