Skip to content

1100 校庆

2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆,校友会收集了所有校友的身份证号。现在需要请你编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。

输入格式:

输入在第一行给出不超过 105 的正整数 N,随后 N 行,每行给出一位校友的身份证号(18 位由数字和大写字母 X 组成的字符串)。题目保证身份证号不重复。

随后给出前来参加校庆的所有人士的信息:首先是一个不超过 105 的正整数 M,随后 M 行,每行给出一位人士的身份证号。题目保证身份证号不重复。

输出格式:

首先在第一行输出参加校庆的校友的人数。然后在第二行输出最年长的校友的身份证号 —— 注意身份证第 7-14 位给出的是 yyyymmdd 格式的生日。如果没有校友来,则在第二行输出最年长的来宾的身份证号。题目保证这样的校友或来宾必是唯一的。

输入样例:

tex
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042

输出样例:

tex
3
150702193604190912
3
150702193604190912

Solution:

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

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());
        Set<String> mate = new HashSet<>();
        for (int i = 0; i < n; i++) {
            mate.add(in.readLine());
        }
        int m = Integer.parseInt(in.readLine());
        int cnt = 0;
        String old, age = "20200101", oldId = "";
        for (int i = 0; i < m; i++) {
            String s = in.readLine();
            String birth = s.substring(6, 14);
            if (age.compareTo(birth) > 0) {
                age = birth;
                oldId = s;
            }
            if (mate.contains(s)) cnt++;
        }
        System.out.println(cnt);
        System.out.println(oldId);
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

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());
        Set<String> mate = new HashSet<>();
        for (int i = 0; i < n; i++) {
            mate.add(in.readLine());
        }
        int m = Integer.parseInt(in.readLine());
        int cnt = 0;
        String old, age = "20200101", oldId = "";
        for (int i = 0; i < m; i++) {
            String s = in.readLine();
            String birth = s.substring(6, 14);
            if (age.compareTo(birth) > 0) {
                age = birth;
                oldId = s;
            }
            if (mate.contains(s)) cnt++;
        }
        System.out.println(cnt);
        System.out.println(oldId);
    }
}

Released under the MIT License.