1157 Anniversary (25 分)

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

经验总结:

题目不难,就是,嗯.....逻辑得理清楚,这一题我没有追求速度使用字符数组,而是string类型,因为考试主要追求的是高效的实现目标。要注意两个人年龄的比较,以及整体的代码逻辑,不太好叙述= =,详细的请看代码吧~~

AC代码

#include <cstdio>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
using namespace std;
map<string, bool> mp;
bool cmp(string a, string b)
{if (a.substr(6, 4) != b.substr(6, 4))return a.substr(6, 4) < b.substr(6, 4);if (a.substr(10, 2) != b.substr(10, 2))return a.substr(10, 2) < b.substr(10, 2);return a.substr(12, 2) < b.substr(12, 2);
}
int main()
{int n,m;string str,temp;scanf("%d", &n);for (int i = 0; i < n; ++i){cin >> str;mp[str] = true;}scanf("%d", &m);bool flag=false;int count = 0;for (int i = 0; i < m; ++i){cin >> str;if (mp[str] == true){if (flag == false){flag = true;temp = str;}else{if (cmp(temp, str) == false)temp = str;}++count;}else{if (i == 0)temp = str;else{if (flag==false&&cmp(temp, str) == false)temp = str;}}}if (flag == true)printf("%d\n%s", count, temp.c_str());elseprintf("0\n%s", temp.c_str());return 0;
}

PAT 甲级 1157 Anniversary相关推荐

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

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

  2. PAT甲级1157 Anniversary

    思路 用两个map存储输出的两部分id,mapp1存储校友的id,mapp2存储出席的id.当输入出席id时,用mapp1.find()函数搜索是否为校友,若是则sum++,并将该id记为1:否则记为 ...

  3. PAT 1157 Anniversary

    1157 Anniversary (25 分) Zhejiang University is about to celebrate her 122th anniversary in 2019. To ...

  4. 2020年9月PAT甲级满分必备刷题技巧

    2020年7月的考试结束了,除了本次的考题更新,短期内不会更新. [7月题目的特点:首次线上考试,没出链表.树相关的模板题,第2到4题背景新颖,大大降低了抄袭历年代码的可能性,可以看作是线上考试的新趋 ...

  5. 2019年12月PAT甲级满分备考经验

    PAT甲级满分备考经验 答题过程 备考经验 答题过程   总得来说,我觉得我幸运,碰上了一次PAT甲级题目相当简单(1085中有190人满分),最终提前一小时交卷,实时排名为35.   我按照1 2 ...

  6. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  7. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  8. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

  9. Pat甲级 1002 A+B for Polynomials

    Pat甲级 1002 A+B for Polynomials 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems ...

最新文章

  1. 零起点学算法17——比较2个数大小
  2. 硬核浪漫还看焊武大帝
  3. PHP生成验证码图片
  4. 【机器学习】Lasso回归(L1正则,MAP+拉普拉斯先验)
  5. 03-05 APP自动化测试-常用定位方式
  6. 安装Linux操作系统
  7. 2016网易研发题目
  8. 安卓手机状态栏 定位服务自动关闭_【科普知识】手机多久关机一次?看完才知道白用那么多年手机了!...
  9. (1) 创建一个Customer ,名字叫 Jane Smith, 他有一个账号为1000,余额为2000元,年利率为 1.23% 的账户。 (2) 对Jane Smith操作。 存入 100 元,再
  10. java filter 重定向_在Filter的doFilter中进行重定向 出现异常
  11. 手工定制眼镜将风靡中国(lyy bros)
  12. SimpleMind Pro 1.29.1 小巧的思维导图工具
  13. 长安车机升级公版高德
  14. 离婚后发现对方婚内出轨,还能否要赔偿
  15. 灿烂星空,你是真的英雄
  16. 【某航】关联规则分析CatalogCrossSell数据集——数据挖掘导论
  17. 分享15个全球顶尖的AIGC图片生成平台
  18. Matlab基础知识-- A\b与b/A的区别
  19. 台式计算机开关电源的电压规格,开关电源电压如何调整如我的电脑开关电源有12V的直流电我想调整为14V的直流为其它电器供电,应该如何调整...
  20. mysql导入亿级数据_如何将上亿条大容量数据导入MYSQL

热门文章

  1. NXP RT1064学习笔记(六)— RTC
  2. Bert代码详解及模型介绍
  3. (云服务器+JQuery+JS+BootStrap+Navicat+AJAX+JavaScript)第一个前端小项目【面试】
  4. csrf(csrf请求非法是什么意思)
  5. 以下未发布-Android的多线程以及异步消息处理机制,android移动开发基础案例教程源码
  6. Java+MySQL基于SSM的二手玩具交换网站
  7. 什么是Socket?websocket和socket区别?
  8. H.265/HEVC简介
  9. visual Studio Code(VS code)软件中HTML超级好用的一个插件 liveserver,vs code浏览网页
  10. 左耳听风 第二十一周