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. flex布局解说和属性

    1. flex-direction 规定当前DIV下面的子元素是横向布局还是纵向布局 row 默认值,横向布局相当于float:left column 纵向,相当于DIV默认的垂直方向 2.justi ...

  2. sqlserver创建索引语句

    CREATE INDEX PersonIndex ON 表名 (字段名)   DROP INDEX PersonIndex ON 表名

  3. 微信支付公众号支付redirect_uri域名与后台配置不一致,错误码10003

    最近弄微信支付,微信支付公众号支付redirect_uri域名与后台配置不一致,错误码10003,最容易出错两个地方 1,appid 对应不到 2,开发者网页授权 填写域名 文章来自http://ww ...

  4. P5468 [NOI2019]回家路线

    传送门 看题目一眼斜率优化,然后写半天调不出来 结果错误的 $dfs$ 有 $95$ 分?暴力 $SPFA$ 就 $AC$ 了? 讲讲正解: 显然是斜率优化的式子: 先不考虑 $q_{s_k}$ 的贡 ...

  5. 【JAVA】 03-Java中的异常和包的使用

    链接: 笔记目录:毕向东Java基础视频教程-笔记 GitHub库:JavaBXD33 目录: <> <> 内容待整理: 异常 异常和错误的发生和区别 异常:java运行期间发 ...

  6. 根据select选择来控div是否显示,默认这个div是隐藏的,

    <!DOCTYPE html><html><head lang="cn"><title>Insert title here</ ...

  7. 从0构建webpack开发环境(三) 开发环境以及 webpack-dev-server 的使用

    sourceMap 实际应用开发过程中大部分时间都是处于开发模式中,其中需要频繁的修改代码.调试和打包. 但是打包后的代码多个模块压缩到了一个bundle文件,如果出现警告或者异常很难定位到具体模块和 ...

  8. Pjsip Porting to Hisilicon SOC

    1)HiSilicon Compiler arm-himix100-linux.tgz or arm-himix100-linux.tgz #Installation instructions are ...

  9. printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vsprintf, vsnprintf - 输出格式转换

    总览 (SYNOPSIS) #include <stdio.h> int printf(const char *format, ...); int fprintf(FILE *stream ...

  10. 一、Api

    一. private static readonly IList<string> BaseParamKey = new List<string>() { "apiId ...