题目
代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//字符串个数
int n=Integer.parseInt(br.readLine());
//字符串
String[] str=new String[n];
for (int i=0;i<n;i++){
str[i]=br.readLine();
}
if (isDirctionarySort(str)&&isLengthSort(str)){
System.out.println("both");
}else if (isDirctionarySort(str)){
System.out.println("lexicographically");
}else if (isLengthSort(str)){
System.out.println("lengths");
}else {
System.out.println("none");
}
}
//字典排序
public static boolean isDirctionarySort(String[] str){
for (int i=0;i<str.length-1;i++){
//compareTo就是比较每个字符的ASCII值
if (str[i].compareTo(str[i+1])>0){
return false;
}
}
return true;
}
//长度排序
public static boolean isLengthSort(String[] str){
for (int i=0;i<str.length-1;i++){
if (str[i].length()>str[i+1].length()){
return false;
}
}
return true;
}
}