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 ...
随机推荐
- python学习第十一天列表的分片和运算
列表的分片也叫切片,也就是从列表中取出一段赋值给另外一个变量,列表运算就是可以进行比较运算,连接运算,乘法运算等. 1,列表的分片 n1=[1,2,3,4,5,6,7,8,9] n2=[1:3] 包含 ...
- Android APP 登陆模块
首先我想强调一点.这个登陆的模块最好是放在另外一个线程里面来实现.否则有可能会爆出一系列的问题, 然后再与主UI 交互.这样就不会爆ANR异常 1.对于登陆模块的.首先大体的逻辑肯定是要清晰的. ...
- NGUI的输入框的校验(input filed script)
一,我们制作一个输入框,右键添加Sprite ,给Sprite添加一个child的label,然后给Sprite添加一个box collider,接着添加input filed script,将lab ...
- 【ASE高级软件工程】Alpha 阶段 backend组 scrum1 记录
本次会议于11月4日,19:10 在微软北京西二号楼13478召开,持续40分钟. 与会人员:Haifeng Chen, Zhikai Chen, Hao Wang, Jia Ning 请假: Xin ...
- redis限流器的设计
1.定义注解 import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java. ...
- 微信小程序(9)--音频及视频弹幕
记录微信小程序音频及视频弹幕播放效果. 1.audio <!-- audio.wxml --> <audio poster="{{poster}}" name=& ...
- Deepin学习笔记
更改更新源 1)sudo vim /etc/apt/sources.list 2)sudo apt-get update 3) 镜像源 http://mirrors.aliyun.com/deepi ...
- 线程中的sleep()、join()、yield()方法有什么区别?
sleep().join().yield()有什么区别? sleep() sleep() 方法需要指定等待的时间,它可以让当前正在执行的线程在指定的时间内暂停执行,进入阻塞状态,该方法既可以让其他同优 ...
- 13.以太坊中web3访问合约账户出现问题——2019年09月29日
title: 合约交互时发现访问不了地址的bug date: "2019-09-29 10:17:16" tags: Dapp开发 categories: 技术驿站 在编写合约交互 ...
- SSH配置与修改
ssh文件路径:/etc/ssh/ ssh的日志文件:/var/log/secure 端口修改:./sshd_config 服务启停: service sshd start/stop/restart ...