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 (≤105). 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). 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

思路:

没啥坑点,正常模拟就行,用map会方便一点

#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<string, int>alum;
map<string, int >guest;
map<string, int>comealum;
int main()
{int n; cin >> n;string s;for (int i = 1; i <= n; ++i){cin >> s;alum[s] = 1;}int m; cin >> m;for (int i = 1; i <= m; ++i){cin >> s;guest[s] = 1;if (alum[s] == 1){comealum[s] = 1;}}cout << comealum.size()<<endl;string ans = "";string tmp = "9";if (comealum.size() == 0){for (auto it = guest.begin(); it != guest.end(); it++){string ss=it->first;string s = ss.substr(6, 8);if (s < tmp){tmp = s;ans = ss;}}}else{for (auto it = comealum.begin(); it != comealum.end(); it++){string ss = it->first;string s = ss.substr(6, 8);if (s < tmp){tmp = s;ans = ss;}}}cout << ans << endl;
}

PAT 1157 Anniversary相关推荐

  1. PAT 甲级 1157 Anniversary

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

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

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

  3. PAT甲级1157 Anniversary

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

  4. 1157 Anniversary

    Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...

  5. PAT 1157:校庆

    题目 中文翻译 代码 #include <iostream> #include <string> #include <unordered_set>using nam ...

  6. 1157 Anniversary (25 分) c++

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

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

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

  8. 力扣PTA~每天至少三题

    文章目录 算法 双指针 平方数之和 167.两数之和-输入有序数组 Reverse Vowels of a string 二分法 153. Find Minimum in Rotated Sorted ...

  9. 『1157』Anniversary

    Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...

最新文章

  1. SSH服务审计工具ssh-audit
  2. python config
  3. ivy maven_将Maven与Ivy集成
  4. web服务器文档根目录在哪里,web服务器根目录在哪
  5. Java模拟事务Demo
  6. Android入门逆引手册 - 12 评分条(RatingBar)的使用
  7. java entry迭代,如何迭代Entry / BarEntry ArrayList并修改它们的值MPAndroid Chart
  8. linux mutt 使用指南,linux mutt详解
  9. 地图点击区域高亮 vue_这个Excel技巧很强大,鼠标点击即高亮显示数据区域
  10. 结对编程-四则运算生成
  11. oracle dba_tables degree default,oracle中如何将表的并行度设定为DEFAULT?如下:
  12. 国内机场代码(IATA)
  13. 逗游怎么安装计算机丢失文件,原神PC版常见安装问题解决方法汇总
  14. 特征点法光流法直接法
  15. 如何在线制作二维码?学校通知二维码的3种制作方法
  16. 保护水资源公益网站html,保护水资源公益广告词
  17. Linux第7章Gdk及Cairo基础,GNOME 平台的2D图形编程(GTK,GDK,Cairo...) 简介 [转]...
  18. dota2游戏心得
  19. Android webview Input type=file 文件上传 解决方法
  20. Android中如何使用代码打开各种类型的文件

热门文章

  1. 面试题——登录、支付功能测试点总结
  2. PXC 安装 (yum操作)
  3. 巨准拓客CRM【工商财税】行业获客解决方案
  4. 关于AI测试与评价的讨论
  5. 易科 Exact Globe Next 销售订单 请求日期(ETD)比发货日期提前5天
  6. 7-11 到底是不是太胖了(10 分)
  7. 干货 | 这些年,我用的绘图工具大合集
  8. matlab用正弦做随机信号程序,(MATLAB辅助现代工程数字信号处理)第6章平稳随机信号处理与分析.ppt...
  9. MySql自定义函数的定义和使用
  10. HCL Nomad 1.0.9中的新功能