当前位置:网站首页>Pat 1157: school anniversary

Pat 1157: school anniversary

2022-06-24 08:19:00 Duange

subject

 Insert picture description here
 Insert picture description here

Chinese translation

 Insert picture description here

Code

#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

int main()
{
    int n,m;
    cin>>n;
    
    unordered_set<string>hash;
    while(n--)
    {
        string name;
        cin>>name;
        hash.insert(name);
    }
    
    cin>>m;
    string a,b;
    int cnt=0;
    while(m--)
    {
        string name;
        cin>>name;
        if(hash.count(name))
        {
            cnt++;
            if(a.empty() || a.substr(6,8)>name.substr(6,8)) a=name;
        }
        
        if(b.empty() || b.substr(6,8) >name.substr(6,8)) b=name;
        
    }
    
    cout<<cnt<<endl;
    if(cnt) cout<<a<<endl;
    else cout<<b<<endl;
    
    return 0;
}
原网站

版权声明
本文为[Duange]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240454564567.html