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 (≤10​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(≤10​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

解题思路:字符串处理,先记录一下所有的alumni,在遍历guest的时候找到alumni有的号码,输出这些号码中最老的一个(即出生日期最小)注意如果一个都没有要输出guest中出生日期最小的。

#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(){int n, m, cnt = 0;string ans, minn;map<string, int>mp;scanf("%d", &n);for(int i = 1; i <= n; ++ i){string temp;cin >> temp;mp[temp] = i;}scanf("%d", &m);for(int i = 0; i < m; ++ i){string temp, tempbirth;cin >> temp;tempbirth = temp.substr(6, 8);if(mp[temp] > 0){if(cnt ++ == 0 || tempbirth < minn){minn = tempbirth;ans = temp;}}if(cnt == 0){if(i == 0 || tempbirth < minn){minn = tempbirth;ans = temp;}}}printf("%d\n%s",cnt, ans.c_str());
}

PAT2019春7-2 Anniversary (25 分)(C++)相关推荐

  1. 1157 Anniversary (25 分) c++

    #include <bits/stdc++.h> using namespace std;bool cmp(string a,string b){return a.substr(6,8)& ...

  2. 19年春季第二题 PAT甲级 1157 Anniversary(25 分)

    英文题目 Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the cel ...

  3. 12门课100分直博清华!这份成绩单冲上热搜,但学霸小伙也曾考过25分

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 金磊 明敏 发自 凹非寺 量子位 报道 | 公众号 QbitAI 一 ...

  4. PTA 7-3 旅游规划 (25分)(双权值Dijkstra最短路)

    7-3 旅游规划 (25分) 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路 ...

  5. PTA 03-树1 树的同构 (25分)

    题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/711 5-3 树的同构   (25分) 给定两棵树T1和T2.如果T1可以通过若干次左右 ...

  6. 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)

    1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  7. 【PAT (Advanced Level) Practice】1093 Count PAT‘s (25 分)

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  8. 【PAT (Advanced Level) Practice】1149 Dangerous Goods Packaging (25 分)

    1149 Dangerous Goods Packaging (25 分) When shipping goods with containers, we have to be careful not ...

  9. 7-29 修理牧场 (25 分)

    7-29 修理牧场 (25 分) 农夫要修理牧场的一段栅栏,他测量了栅栏,发现需要N块木头,每块木头长度为整数L ​i ​​ 个长度单位,于是他购买了一条很长的.能锯成N块的木头,即该木头的长度是L ...

  10. 7-18 银行业务队列简单模拟 (25 分)

    7-18 银行业务队列简单模拟 (25 分) 设某银行有A.B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 -- 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客.给定到达 ...

最新文章

  1. DCN-2655 ssh 远程登陆配置
  2. 从此以后,江湖有了它的传说!
  3. 能跑TensorFlow,能唱KTV,这是国产车吉利的智能系统和背后的芯片
  4. 关系代数的自然连接符号_初中数学知识清单之代数式的认识
  5. hadoop学习笔记(二):centos7三节点安装hadoop2.7.0
  6. C# 对程序窗口进程和进程ID
  7. “国家科学数据中心”联合专刊征稿
  8. 观察者模式与职责链模式的相同和不同_GOF设计模式(策略模式,职责链模式)...
  9. Vue项目报错:This relative module was not found
  10. 使用自定义功能构建Mamdani系统
  11. 适配器模式之观察者模式
  12. 百度网盘文件真实地址解析
  13. (Modern Family S01E03) Part4  PhilClaire  Gloria和Luke到Claire家玩 Claire和Luke谈心
  14. PHP在线考试系统源码 在线答题 在线批改
  15. 目标文件夹访问被拒绝,您需要权限来执行此操作
  16. ICPC North Central NA Contest 2017 H.Zebras and Ocelots
  17. 如何下载微信公众号的音频文件
  18. python序列的应用
  19. Eclipse调试python
  20. (14)python函数与变量

热门文章

  1. python跟易语言的爬虫_用易语言写个简单的小爬虫其中的关键点
  2. [BZOJ2879][Noi2012]美食节(费用流)
  3. 【C语言】sizeof(数组名),包括 一维数组、字符数组、二维数组
  4. 费了九牛二虎之力搞到的python精选库,不看会后悔
  5. 国际现货黄金走势图如何分析?
  6. Eclipse注释模板图文详解
  7. 布局中的QTableWidget()如何设置整个表格可以拉伸
  8. 关于ida pro的牛逼插件keypatch
  9. 程序员毕业4年想在北京买房被网友嘲讽,晒出存款,网友:很励志
  10. 鱼菜共生环境下的鱼类氮利用优化研究计划