作者:
LaLa_JUROU
,
2023-05-24 12:31:57
,
所有人可见
,
阅读 9
//二维数组的排序
//二维dp,空间换时间
import java.io.*;
public class Main{
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static int dp[][],sort[]; //dp的索引0存储数组长度
static char line[];
public static void main(String[] args) throws IOException{
String sr = in.readLine();
while(sr != null) {
line = sr.toCharArray();
dp = new int[100][10001];
sort = new int[line.length + 1];
for(int i = 0 ; i < sort.length; i ++) {//预处理
sort[i] = -1;
}
for(int i = 0; i < line.length; i ++) {//动态分组
if(line[i] >= 65 && line[i] <= 122) {
int index = (line[i] - 65) % 32; //不区分大小写
dp[index][dp[index][0] + 1] = line[i];
dp[index][0] ++;
} else {
sort[i] = line[i];
}
}
//将字符重新排列到sort中
int index = 0;
for(int i = 0; i < dp.length; i ++) {
for(int o = 1; o < dp[i].length; o ++) {
while(sort[index] != -1) {//指针移动到需要插入的位置
index ++;
}
if(o > dp[i][0]) {
break;
}
sort[index] = (char)dp[i][o];
}
}
for(int i = 0; i < sort.length - 1; i ++) {
out.print((char)sort[i]);
}
out.println();
out.flush();
}
}
}