import java.io.IOException;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
class Main
{
public static final boolean DEBUG = false;
public static void main(String[] args) throws IOException
{
BufferedReader cin;
String s;
if (DEBUG) {
cin = new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt"));
} else {
cin = new BufferedReader(new InputStreamReader(System.in));
}
while ((s = cin.readLine()) != null) {
if (s.length() == 0) continue;
int n = Integer.parseInt(s);
int i;
String[] str = new String[n];
for (i = 0; i < n; i++) {
s = cin.readLine();
if (s.compareTo("stop") == 0) {
break;
}
str[i] = s;
}
Comparator<String> cmp = new Comparator<String>() {
public int compare(String a, String b) {
return a.length() - b.length();
}
};
Arrays.sort(str, 0, i, cmp);
for (int j = 0; j < i; j++) {
System.out.println(str[j]);
}
}
}
}
题目1135:字符串排序
最新推荐文章于 2022-10-03 18:31:54 发布