题目链接:POJ3617
题解:
import java.util.Scanner;
public class Practice_字典序最小问题 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
StringBuilder ss = new StringBuilder();
for (int i = 0; i < N; i++) {
ss.append(in.next());
}
f(ss.toString(), N);
}
static int cnt;
private static void f(String str, int n) {
String s1 = new StringBuilder(str).reverse().toString();//反转后的字符串
StringBuilder res = new StringBuilder();
cnt = 0;
while (res.length() < n) {
if (str.compareTo(s1) > 0) {
res.append(s1.charAt(0));
s1 = s1.substring(1);
} else {
res.append(str.charAt(0));
str = str.substring(1);
}
if (s1.length() % 80 == 0) {
System.out.println(res.substring(cnt * 80, (cnt + 1) * 80));
cnt++;
}
}
//打印余数部分
if (res.length() > cnt * 80) {
System.out.println(res.substring(cnt * 80));
}
}
}