1100 校庆 pat乙级真题

思路:哈希 + sort排序

哈希用map容器

比较年份很简单,数字越小年份越早,年龄越大,比如19691225  和 19681224,前者数字更大,所以年龄更小

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

map <string,bool> mp; 

bool cmp(const string &s1, const string &s2) {
  	return s1.substr(6,8)<s2.substr(6,8);
}

int main(){
    int n1;cin>>n1;
    string s1[100010];
    for(int i =0;i<n1;i++){
        cin>>s1[i];
        mp[s1[i]] = true;
    }
    int n2;cin>>n2;
    string s2[100010]; int count=0;
    for(int i =0;i<n2;i++) {
        cin>>s2[i];
        if(mp[s2[i]]) count++;
    }
   printf("%d\n",count);
   
	sort(s2,s2+n2,cmp);
        if(count==0) cout<<s2[0];
        else{
        	for(int i =0;i<n2;i++) if(mp[s2[i]]) {cout<<s2[i];break;}
		}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值