世界太喧闹,不如敲代码。

直接上题目:


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


说白了就是给两组名单,一组是来访校友,一组是真正来了的嘉宾,要求输出最老的来访校友的ID,如果没有校友那么输出最老嘉宾的名单,同时还要输出来访的校友的总人数。

代码:

#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std; bool cmp(string a, string b) {
return a.substr(6, 8) < b.substr(6, 8); // 就是直接比较字符串大小,因为ASCII里面越大的数字反而对应的数字越小,例如'1984' < '1998'
} int main() {
string name;
int a_num, g_num;
unordered_map<string, bool> find_alu;
vector<string> all_guest, alu_list;
cin >> a_num;
for (int i = 0; i < a_num; ++i) {
cin >> name;
find_alu[name] = true; // 建立映射map,string -> bool,用来判定一个ID是不是属于校友列表的
}
cin >> g_num;
for (int i = 0; i < g_num; ++i) {
cin >> name;
all_guest.push_back(name);
if (find_alu[name]) alu_list.push_back(name); // 如果是校友那么就把ID添加到校友名单中
}
printf("%d\n", alu_list.size());
if (!alu_list.empty()) {
sort(alu_list.begin(), alu_list.end(), cmp); // 用STL的方法来进行排序
printf("%s\n", alu_list[0].c_str());
}
else {
sort(all_guest.begin(), all_guest.end(), cmp);
printf("%s\n", all_guest[0].c_str());
}
return 0;
}

这里的代码依旧是和上一篇一样,作者是merely尘埃,我稍微改动了下。

C++笔记(1)——Anniversary的更多相关文章

  1. <老友记>学习笔记

    这是六个人的故事,从不服输而又有强烈控制欲的monica,未经世事的千金大小姐rachel,正直又专情的ross,幽默风趣的chandle,古怪迷人的phoebe,花心天真的joey——六个好友之间的 ...

  2. 经济学人精读笔记9:打出租out了,“飞的”时代要来了!

    经济学人精读笔记9:打出租out了,"飞的"时代要来了! 标签(空格分隔): 经济学人 Part 1 Flying taxis are taking off to whisk pe ...

  3. git-简单流程(学习笔记)

    这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...

  4. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  5. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  6. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  7. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  8. NET Core-学习笔记(三)

    这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...

  9. springMVC学习笔记--知识点总结1

    以下是学习springmvc框架时的笔记整理: 结果跳转方式 1.设置ModelAndView,根据view的名称,和视图渲染器跳转到指定的页面. 比如jsp的视图渲染器是如下配置的: <!-- ...

随机推荐

  1. netstat Recv-Q和Send-Q判断包在哪端

    通过netstat -anp可以查看机器的当前连接状态:   Active Internet connections (servers and established) Proto Recv-Q Se ...

  2. 锁&lock与latch

    锁是数据库系统区别于文件系统的一个关键特性.锁机制用于管理对共享资源的并发访问.Innodb不仅仅使用行锁,也会在数据库内部其它地方使用锁,从而允许对多种不同资源提供并发访问.如:操作缓冲池中的LRU ...

  3. 题解 [SHOI2010]最小生成树

     题面 解析 看上去是黑题啊! 实际上也就是道网络流最大流. 当然,我们也知道网络流最关键的是建图. 首先,分析一下题目: 题目要求在操作后使给定的边lab一定在最小生成树上, 求最小的操作数. 先设 ...

  4. Can't specify target table for update in FROM clause

    UPDATE tbl SET col = ( SELECT ... FROM (SELECT.... FROM) AS x); 额外嵌套了一个 SELECT 语句 例如LeetCode 中的 Dele ...

  5. 33. ClustrixDB 扩展集群的容量-Flex up

    ClustrixDB被授权为每个节点的最大核数以及集群的最大节点数.如果需要扩展许可证,请联系Clustrix Sales.扩容之前检查License是否支持节点数. 一.准备节点 提供节点并在每个节 ...

  6. Mysql主从同步 异常Slave_SQL_Running: No

    在刚搭建好的mysql主从节点上对从节点进行操作,导致同步异常:报错如下: 从节点执行: mysql> show slave status\G;************************* ...

  7. MySQL_8.0与5.7区别之账户与安全

    一.创建用户和用户授权 MySQL5.7创建用户和用户授权命令可以同时执行 grant all privileges on *.* to 'Gary'@'%' identified by 'Gary@ ...

  8. web 新能优化

    网上的东西太多了都是搜来的东西 留着自己看吧! 摘自 :http://www.cnblogs.com/50614090/archive/2011/08/19/2145620.html 打开网站慢现状分 ...

  9. [题解] [bzoj2622] 深入虎穴

    题解 题解 考虑到正着跑不好想, 我们尝试反向跑 以每个终点作为起点, 维护每个点的最小值和次小值(最小的被老虎ban掉了) 转移的时候用当前点的次小值去更新其所连的点的最小值和次小值 由于最小的次小 ...

  10. Windows下Yarn安装与使用

    参考博客 1.安装yarn 方法一:使用安装包安装 官方下载安装包,https://yarnpkg.com/zh-Hans/docs/install,安装完毕后,一定要配置环境变量. 方法二:使用np ...