输出未能排序
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n =sc.nextInt();
sc.nextLine();
String[] ID =new String[n];
for (int i=0;i<n;i++) {
ID[i]=sc.nextLine();
}
for (int i=0;i<n;i++) {
for (int j=i;j<n-1;j++) {
if (Integer.parseInt(ID[j].substring(6,10))>Integer.parseInt(ID[j+1].substring(6,10))) {
String Tmp = ID[j];
ID[j] =ID[j+1];
ID[j+1]= Tmp;
}else if(Integer.parseInt(ID[j].substring(6,10))==Integer.parseInt(ID[j+1].substring(6,10))){
if(Integer.parseInt(ID[j].substring(10,12))>Integer.parseInt(ID[j+1].substring(10,12))){
String Tmp = ID[j];
ID[j]=ID[j+1];
ID[j+1]=Tmp;
}
else if (Integer.parseInt(ID[j].substring(10,12))==Integer.parseInt(ID[j+1].substring(10,12))){
if (Integer.parseInt(ID[j].substring(12,14))>Integer.parseInt(ID[j+1].substring(12,14))) {
String Tmp =ID[j];
ID[j]=ID[j+1];
ID[j+1]=Tmp;
}
}
}
}
}
for(;;) {
String tmp=sc.nextLine();
if (tmp.equals("sort1"))
{
for(int i=0;i<n;i++) {
System.out.println(ID[i].substring(6,10)+"-"+ID[i].substring(10,12)+"-"+ID[i].substring(12,14));
}
}else if (tmp.equals("sort2")) {
for (int i=n-1;i>=0;i--) {
System.out.println(ID[i]);
}
}else{
System.out.println("exit");
break;
}
}
}
}