校庆

题目 校庆

image-64766e43

思路分析

看是否出现过 用unordered_set即可

看年长只要看身份证7~14位谁更小即可 因为从1开始而程序从0 其实就是从6截取8长度

代码实现

#include<bits/stdc++.h>

using namespace std;

unordered_set<string> h;

int n,m;

int main()

{

    cin>>n;

    while(n--){

        string name;

        cin>>name;

        h.insert(name);

    }

    cin>>m;

    string all_older,come_older;

    int cnt=0;

    while(m--){

        string name;

        cin>>name;

        if(h.count(name)){

            cnt++;

            if(all_older.empty() || all_older.substr(6,8)>name.substr(6,8))

                all_older=name;

        }

        if(come_older.empty() || come_older.substr(6,8)>name.substr(6,8))

            come_older=name;

    }

    cout<<cnt<<endl;

    if(cnt)

        cout<<all_older<<endl;

    else

        cout<<come_older<<endl;

    return 0;

}

同类题型

视频讲解


⬅️ 最大数量 🏠 00-刷题理模型 ➡️ 电话号码