1028 人口普查 (20分) -java

/**
 * @author :zxq
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        long maxAge = 20140907L, minAge = 18140905L;
        String maxName = "", minName = "";
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            String[] strings = in.readLine().split(" ");
            String[] ymd = strings[1].split("/");
            long birth = Long.parseLong(ymd[0]) * 10000 + Long.parseLong(ymd[1]) * 100 + Long.parseLong(ymd[2]);
            if (birth >= 18140906 && birth <= 20140906) {
                cnt++;
                if (birth < maxAge) {
                    maxAge = birth;
                    maxName = strings[0];
                }
                if (birth > minAge) {
                    minAge = birth;
                    minName = strings[0];
                }
            }
        }
        if (cnt > 0) {
            System.out.println(cnt + " " + maxName + " " + minName);
        }else {
            System.out.println("0");
        }
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容