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. luoguP1505 [国家集训队]旅游(真的毒瘤)

    luogu P1505 [国家集训队]旅游 题目 #include<iostream> #include<cstdio> #include<cstdlib> #in ...

  2. php实现字符串翻转,使字符串的单词正序,单词的字符倒序

    如字符串'I love you'变成'I evol uoy',只能使用strlen(),不能使用其他内置函数. function strturn($str){ $pstr=''; $sstr=''; ...

  3. 爬虫之requests模块的使用

    requests模块 概念:基于网络请求的模块 作用:用来模拟浏览器发请求,从而实现爬虫 环境安装:pip install requests 编码流程: 指定url 发起请求 获取响应数据 持久化存储 ...

  4. 75.Binary Tree Maximum Path Sum(二叉树的最大路径和)

    Level:   Hard 题目描述: Given a non-empty binary tree, find the maximum path sum. For this problem, a pa ...

  5. sublime text3 安装插件

    遇到的问题1: 软件中无此属性 打开Packages目录,Preferences > Browse Packages 就可以进入这个目录.$ cd Packages/$ git clone ht ...

  6. U盘装CENTOS操作系统

    一.制作U盘系统镜像 1).用UltralISO软件打开下载好的ISO文件镜像,“文件”-“打开”,选中下载好的ISO镜像 2)点击“启动”-“写入硬盘镜像”,选中需要写入的U盘(容量最少为8G),点 ...

  7. ltp-ddt genload

    under folder tools\genload   genload.c             "`%s' imposes certain types of compute stres ...

  8. mysql安装 demo [linux centos7] [5.7.26]

    MySQL 安装配置 https://www.runoob.com/linux/mysql-install-setup.html =================================== ...

  9. phpstorm ftp不能连接服务器

    环境: ubuntu phpstorm 问题一. 服务器ftp功能没有开启 解决方法:在服务器上安装 ftp 服务 https://i.cnblogs.com/EditPosts.aspx?posti ...

  10. BZOJ5261 Rhyme

    传送门 广义后缀自动机= =+ 跟ptx大爷的博客学的 戳我传送 我写的第一种 建立Trie树的写法 bfs建立SAM 为什么是bfs呢 我也不知道(GG) 经过我一番抱大腿+询问 各位大爷说的原因是 ...