哈哈哈哈, 又用Java强大的字符串API和集合类水过一道题,不服用C++来一遍看看比这个代码长多少(不考虑时间的情况下)。
import java.util.*;
public class Main1584 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> arrlist = new ArrayList<String>();
String s;
int n;
n = scan.nextInt();
while(n-- > 0) {
arrlist.clear();
s = scan.next();
arrlist.add(s);
for(int i=1; i<s.length(); i++) {
StringBuilder strB = new StringBuilder();
strB.append(s.substring(i));
strB.append(s.substring(0, i));
arrlist.add(strB.toString());
}
Collections.sort(arrlist);
System.out.println(arrlist.get(0));
}
}
}