import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int total = in.nextInt();       
        int count = 0;
        boolean flag;
        int maxindex = 0;
        int minindex = 0;
        String startday ="2014/09/06";
        String endday = "1814/09/06";
        String names[] = new String[100000];
        String birthdays[] = new String[100000];
        for (int i = 0; i < total; i++) {
            names[i] = in.next();
            birthdays[i] = in.next();
            flag = true;
            if(birthdays[i].compareTo(startday)>0||birthdays[i].compareTo(endday)<0){
                flag = false;
            }   
             if(flag){
                count++;
                if(birthdays[i].compareTo(birthdays[maxindex])<0){
                    maxindex= i;
                }
                else if(birthdays[i].compareTo(birthdays[minindex])>0){
                    minindex= i;
                }
             }else{
                 if(maxindex==i){
                     maxindex++;
                 }
                 if(minindex==i){
                     minindex++;
                 }
             }
        }       
        if(count==0)
            System.out.println(count);
        else
            System.out.println(count+" "+names[maxindex]+" "+names[minindex]);
    }
 
}

java的在PAT官网通过不了最后一组测试,因为超时,以下的c++代码完全可以通过

#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;  // 人数
    int count = 0;  // 生日合理的人数
    cin >> n;
    string minBirth = "3000/00/00", minName = "";
    string maxBirth = "0000/00/00", maxName = "";
    const string start = "1814/09/06";
    const string end = "2014/09/06";
    for(int i = 0 ; i < n ; i++) {
      string name,birth;
      cin >> name >> birth;
      if(birth <= end && birth >= start) {
          count++;  // 记录生日合理的人数
         if(minBirth > birth) {     // 判断最小值(最年长)
              minName = name;
              minBirth = birth;
          }
          if(maxBirth < birth) {    // 判断最大值(最年轻)
              maxName = name;
              maxBirth = birth;
          }
      }
    }
    if(count > 0) {
        cout << count << " " << minName << " " << maxName << endl;
    } else {
        cout << count << endl;
    }
	return 0;
}