PAT甲级【2019年3月考题】——A1157 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 (≤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】的更多相关文章
- PAT甲级【2019年9月考题】——A1164 DijkstraSequence【30】
7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is ...
- PAT甲级【2019年9月考题】——A1163 PostfixExpression【25】
7-3 Postfix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspon ...
- 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 ...
- PAT甲级【2019年9月考题】——A1160 Forever【20】
7-1 Forever (20 分) "Forever number" is a positive integer A with K digits, satisfying the ...
- 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 ...
- PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】
Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting ...
- 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 ...
- PAT甲级2019冬季考试题解
A Good In C纯模拟题,用string数组读入数据,注意单词数量的判断 #include<bits/stdc++.h> using namespace std; ; ][]; in ...
- PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作
给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
随机推荐
- Codeforces - 1195E - OpenStreetMap - 单调队列
https://codeforc.es/contest/1195/problem/E 一个能运行但是会T的版本,因为本质上还是\(O(nmab)\)的算法.每次\(O(ab)\)初始化矩阵中的可能有用 ...
- ADC(简易的DMA传输)的认识
ADC(简易的DMA传输)的认识 首先看到是ADC的特性 1.ADC的12位分辨率.不能直接测量负电压,然后是最小量程化单位是LSB=Vref+/212 2.单次和转换模式的使用 3. 从通道0到通道 ...
- NGUI技能CD效果制作(sprite的type:filled)
一,我们先添加一个sprite,改名为skill.给当前skill添加图片,然后再sprite下添加一个sprite和一个label,结果如下 二现在我们来设置skill下的sprite,给他设置一个 ...
- MySQL数据库使用xtrabackup备份实现小例子
关于MySQL数据库的备份的工具和方式也比较多,本文只简单介绍一些我司一个平台的备份方案.Xtrabackup是由percona开源的免费数据库热备份软件,但是只能对InnoDB数据库和XtraDB存 ...
- Error- Overloaded method value createDirectStream in error Spark Streaming打包报错
直接上代码 StreamingExamples.setStreamingLogLevels() val Array(brokers, topics) = args // Create context ...
- 服务器处理 json 数据
今天做小程序后端,需要处理 json 数据,我用的 express 框架,无法直接处理,需要进行 json 提取,网上找了一堆,发现json 四种解析格式,在此记录一下 www-form-urlenc ...
- Sybase 修改数据库默认排序
我新建了一个sybase数据库,想用dump文件load,可是报数据库的排序不对,就去Centrol里面修改,但是还是报错,说是字符集不存在.办法如下: 打开命令行,进入到sybase的ASE-15_ ...
- 工欲善其事,必先利其器——React Native的 IDE
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yayayaya20122012/article/details/51119801之前的文章中,我们已 ...
- MongoDB 导入导出以及数据库备份
-------------------MongoDB数据导入与导出------------------- 1.导出工具:mongoexport 1.1.概念: mongoDB中的 ...
- jsonp跨域获取数据实现百度搜索
本菜鸡最近在写某个页面请求数据时,报了如下的错误. Failed to load https://...:No 'Access-Control-Allow-Origin' header is pres ...