Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID’s of all her alumni. Now your job is to write a program to count the number of alumni among all the people who come to the celebration.

Input Specification:
Each input file contains one test case. For each case, the first part is about the information of all the alumni. Given in the first line is a positive integer N (≤105 10^510
5
​​ ). Then N lines follow, each contains an ID number of an alumnus. An ID number is a string of 18 digits or the letter X. It is guaranteed that all the ID’s are distinct.

The next part gives the information of all the people who come to the celebration. Again given in the first line is a positive integer M (≤105 10^510
5
​​ ).Then M lines follow, each contains an ID number of a guest. It is guaranteed that all the ID’s are distinct.

Output Specification:
First print in a line the number of alumni among all the people who come to the celebration. Then in the second line, print the ID of the oldest alumnus – notice that the 7th - 14th digits of the ID gives one’s birth date. If no alumnus comes, output the ID of the oldest guest instead. It is guaranteed that such an alumnus or guest is unique.

Sample Input:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
Sample Output:
3
150702193604190912

【声明】

  由于此题还未上PAT官网题库,故没有测试集,仅仅是通过了样例,若发现错误,感谢留言指正。

Solution:

  这道题就是说,浙大举行校区,列了n个贵宾id【身份证】,然后问出席的m个人中有没有贵宾出席,有的话,输出出席的最大年龄贵宾的id,若没有贵宾出席,那么就输出出席人中的最大年龄的id

  这道题就使用unordered_map存储一下贵宾id,然后与出席的人的id对比一下即可,同时找到最大年龄的id

 #include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
int main()
{
int n, m, cnt = ;
cin >> n;
unordered_map<string, bool>map;
string id, oldGuset = "", oldAlumni = "", gusetId, alumniId;//这里最老的人物的年龄使用的是明年的应该可以的
for (int i = ; i < n; ++i)
{
cin >> id;
map[id] = true;//记录通知的人
}
cin >> m;
while (m--)
{
cin >> id;
string str = id.substr(, );//获取出生年月
if (oldGuset > str)//年龄越大,出生时间越早
{
oldGuset = str;
gusetId = id;
}
if (map[id])//此人是贵宾
{
++cnt;
if (oldAlumni > str)
{
oldAlumni = str;
alumniId = id;
}
}
}
printf("%d\n", cnt);
if (cnt > )
printf("%s\n", alumniId.c_str());
else
printf("%s\n", gusetId);
return ;
}

PAT甲级【2019年3月考题】——A1157 Anniversary【25】的更多相关文章

  1. PAT甲级【2019年9月考题】——A1164 DijkstraSequence【30】

    7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is ...

  2. PAT甲级【2019年9月考题】——A1163 PostfixExpression【25】

    7-3 Postfix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspon ...

  3. PAT甲级【2019年9月考题】——A1162 MergingLinkedLists【25】

    7-2 Merging Linked Lists (25 分) Given two singly linked lists L 1 =a 1 →a 2 →...→a n−1 →a n  L1=a1→a ...

  4. PAT甲级【2019年9月考题】——A1160 Forever【20】

    7-1 Forever (20 分) "Forever number" is a positive integer A with K digits, satisfying the ...

  5. PAT甲级【2019年3月考题】——A1159 Structure_of_a_BinaryTree【30】

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...

  6. PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

    Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting ...

  7. PAT甲级【2019年3月考题】——A1156 SexyPrimes【20】

    Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “si ...

  8. PAT甲级2019冬季考试题解

    A Good In C纯模拟题,用string数组读入数据,注意单词数量的判断 #include<bits/stdc++.h> using namespace std; ; ][]; in ...

  9. PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作

    给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...

随机推荐

  1. matlab批量修改变量的名称

    使用matlab做实验的时候,保存的文件里面的变量名都是一样的 ,所以希望能够把变量名全部都重命名.我举个个例子,假设我一堆文件,文件名分别是gds1,gds2,gds2,-.. 但是实际上load进 ...

  2. 浏览器如何减少 reflow/repaint

    1.不要一条一条地修改 DOM 的样式.与其这样,还不如预先定义好 css 的 class,然后修改 DOM 的 className. 2)把 DOM 离线后修改.如: 使用 documentFrag ...

  3. 13-H.264编码解码器的无线应用:1080P60 3D无线影音传输器

    H.264编码解码器的无线应用:1080P60 3D无线影音传输器 一.应用领域 家庭媒体娱乐中心 新闻现场采访 无线3D投影机 高清视频会议终端无线延长器 教学,医疗示教 考古,高档商业区域,监狱等 ...

  4. selenium原理(以百度搜索为例)

    1.首先导入 Selenium(webdriver)相关模块2.调用 Selenium 的浏览器驱动,获取浏览器句柄(driver)并启动浏览器.3.通过句柄访问百度 URL.4.通过句柄操作页面元素 ...

  5. Kafka初识

    1.概述 1.1.Apache Kafka是一个   分布式  流处理   平台: 2.Kafka适应于什么场景? 2.1.构造  实时  流数据管道,在  系统 或 应用之间  可靠地获取数据(相当 ...

  6. less和vim中使用正则表达式搜索

    使用less查看 txt 文件之后,按\可以正则表达式来搜索: less phonelist.txt (232) 298-2265 (624) 381-1078 (540) 126-1980 (874 ...

  7. 修改host,访问指定服务器

    途径: 1.hosts文件修改 以Windows文件为例:进入system32/drivers/etc/hosts 或者用一些软件比如switchhost等来进行修改 2.通过抓包工具修改 因为本人是 ...

  8. Halo(六)

    Spring publish-event 机制 监听者模式包含了一个监听者 Listener 与之对应的事件 Event,还有一个事件发布者 EventPublish. 过程就是 EventPubli ...

  9. MongoDB笔记【1】——安装MongoDB

    SQL - 结构化查询语言 - 关系数据库全都同SQL来操作 1.安装MongoDB - 安装 - 配置环境变量 C:\Program Files\MongoDB\Server\3.2\bin - 在 ...

  10. Activation functions on the Keras

    sigmoid tanh tanh函数定义如下: 激活函数形状: ReLU 大家族 ReLU softmax 函数 softmax是一个函数,其主要用于输出节点的分类,它有一个特点,所以的值相加会等于 ...