测试点5给的数据输出是跟本地输出一样的为何会wa

P1104 生日

Y13113834 @ 2024-02-17 01:19:28

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Person person[] = new Person[n];
        for (int i = 0; i < n; i++) {
            person[i] = new Person();
            person[i].name = sc.next();
            person[i].year = sc.nextInt();
            person[i].month = sc.nextInt();
            person[i].day = sc.nextInt();
            person[i].top = i;
        }
        Arrays.sort(person, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                if (o1.getYear()- o2.getYear()>0) {
                    return -1;
                }else if(o1.getYear()< o2.getYear()) {
                    return 1;
                }else {
                    if (o1.getMonth()-o2.getMonth()>0){
                        return -1;
                    } else if (o1.getMonth()-o2.getMonth()<0) {
                        return 1;
                    }else {
                        if (o1.getDay()> o2.getDay()){
                            return -1;
                        } else if (o1.getDay()<o2.getDay()) {
                            return 1;
                        }else {
                            return -Integer.compare(o1.getTop(), o2.getTop());
                        }
                    }
                }

            }
        });
        for (int i = n-1; i >=0; i--) {
            System.out.println(person[i].toString());
        }
    }
public static class Person{
    String name;
    int year;
    int month;
    int day;
    int top ;

    public int getTop() {
        return top;
    }

    public int getDay() {
        return day;
    }

    public int getMonth() {
        return month;
    }

    public int getYear() {
        return year;
    }

    public String getName() {
        return name;
    }
    public String toString(){
        return name;
    }
}
}

|