PAT 2019-3 7-2 Anniversary
Description:
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 (≤). 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 (≤). 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
Keys:
- 字符串处理
Code:
/*
统计校友会到场的人员信息
校友人数N<=1e5
N个人的ID号
到场人数M<=1e5
M个人的ID号 到场校友的人数
年龄最大的校友ID
如果没有校友到场,打印非校友中年龄最大的ID
*/
#include<cstdio>
#include<string>
#include<unordered_map>
#include<iostream>
using namespace std;
unordered_map<string,int> mp; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDEG int n;
scanf("%d", &n);
for(int i=; i<n; i++)
{
string s;
cin >> s;
mp[s] =;
}
scanf("%d", &n);
string s,s1,s2;
int cnt=;
for(int i=; i<n; i++)
{
cin >> s;
if(mp[s] == )
{
cnt++;
if(s1.size()== || s1.substr(,)>s.substr(,))
s1 = s;
}
else
{
if(s2.size()== || s2.substr(,)>s.substr(,))
s2 = s;
}
}
printf("%d\n", cnt);
if(cnt)
printf("%s", s1.c_str());
else
printf("%s", s2.c_str()); return ;
}
PAT 2019-3 7-2 Anniversary的更多相关文章
- PAT 2019 秋
考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...
- PAT 2019 春
算是第二次做这套题吧,感觉从上次考试到现在自己有了挺大提高,提前30min做完了. 7-1 Sexy Primes 读懂题意就行. #include <cstdio> #include & ...
- PAT甲级【2019年3月考题】——A1157 Anniversary【25】
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...
- 2019秋季PAT甲级_C++题解
2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...
- 2019秋季PAT甲级_备考总结
2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...
- PAT甲级考前整理(2019年3月备考)之三,持续更新中.....
PAT甲级考前整理一:https://www.cnblogs.com/jlyg/p/7525244.html,主要讲了131题的易错题及坑点 PAT甲级考前整理二:https://www.cnblog ...
- PAT甲级考前整理(2019年3月备考)之二,持续更新中.....
PAT甲级考前整理之一网址:https://www.cnblogs.com/jlyg/p/7525244.html,主要总结了前面131题的类型以及易错题及坑点. PAT甲级考前整理三网址:https ...
- PAT甲级考前整理(2019年3月备考)之一
转载请注明出处:https://www.cnblogs.com/jlyg/p/7525244.html 终于在考前,刷完PAT甲级131道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种 ...
- PAT(甲级)2019年春季考试
7-1 Sexy Primes 判断素数 一个点没过17/20分 错因:输出i-6写成了输出i,当时写的很乱,可以参考其他人的写法 #include<bits/stdc++.h> usin ...
随机推荐
- FZU 2187 回家种地 ( 扫描线 + 离散 求矩阵单次覆盖面积 )
2187 回家种地 Accept: 56 Submit: 230Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Descript ...
- LayaBox 常用技巧
1.修改IDE的菜单 找到安装路径的LayaAirIDE\resources\app\out\vs\layaEditor\renders\laya.editorUI.xml 注意事项: 1.mask的 ...
- js的预解析和作用域
预解析指的就是,在js文件或者script里面的代码在正式开始执行之前,进行的一些解析工作.这个工作很简单,就是在全局中寻找var关键字声明的变量和通过function关键字声明的函数. 1.寻找 v ...
- js 程序执行与顺序实现详解
JavaScript是一种描述型脚本语言,由浏览器进行动态的解析与执行,浏览器对于不同的方式有不同的解析顺序,详细介绍如下,感兴趣的朋友可以参考下哈 函数的声明和调用 JavaScript是一种描述型 ...
- 微信小程序(16)-- bindtap,catchtap事件绑定的区别
bindtap,catchtap事件绑定的区别,这里就涉及冒泡事件了.bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡. logs.wxml <view cl ...
- 搭建个人使用服务器-vultr
内容来自https://www.noobyy.com/31.html 谢谢教程,侵权的话会立即删除! 1. 首先进入Vultr官网注册:https://www.vultr.com 注册完开始充值,我 ...
- Codeforces Round #393 (Div. 2) - C
题目链接:http://codeforces.com/contest/760/problem/C 题意:有n个烤串,并且每个烤串起初都放在一个火盆上并且烤串都正面朝上,现在定义p序列,p[i]表示在i ...
- [数论]原根与指标,BSGS
刚学了这方面的知识,总结一下.推荐学习数论方面的知识还是看书学习,蒟蒻看的是<初等数论>学的. 这里也推荐几个总结性质的博客,学习大佬的代码和习题. 原根:https://blog.csd ...
- python基础:10.多线程装饰器模式下的单例模式
with def __enter__ def __close__ 闭包: 装饰器: 闭包的延迟绑定: 单例模式的应用:
- setInterval,setTimeout,clearInterval
定时器 var i=0; function iadd(){ i++; console.log(i) } setInterval(iadd,1000);//1.2.3... 超时调用 var i=0; ...