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

直接上题目:


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. 解决laydate动态设置初始值的问题

    //初始化//注意:我这里是时间范围选择,所以定义了range属性.var timeScope = laydate.render({ elem: '#time_scope', range: '~', ...

  2. IDEA 使用LiveEdit插件

    第一步: 第二步: 第三步: 第四步: 等待下载完成 第五步: 第六步: 第七步: 配置tomcat时注意选择chrome浏览器,并勾选右边的多选框 完成之后,就可以启动项目了,然后可以改变html代 ...

  3. Springboot的resources下资源访问的问题

    对于路径问题,是让我一直感到痛苦的事情,首先是因为我的眼高手低,感觉路径这么简单根本没必要去看,但是昨天项目组长的冷嘲热讽让我无地自容:“你竟然连linux和window的路径的区别都不知道,呵呵”. ...

  4. BZOJ 1778: [Usaco2010 Hol]Dotp 驱逐猪猡 概率与期望+高斯消元

    这个还挺友好的,自己相对轻松能想出来~令 $f[i]$ 表示起点到点 $i$ 的期望次数,则 $ans[i]=f[i]\times \frac{p}{q}$ #include <cmath> ...

  5. 20190716NOIP模拟赛T2 通讯(tarjan缩点+贪心)

    题目描述 “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了中二科学家伦太郎发往过去的一条短 信,并由此得知了伦太郎制作出了电话微波炉(仮). 为了掌握时间机器的技术,SERN总部 ...

  6. 关于int main(int argc,char* argv[])详解

    平时在VS的环境下,主函数总会看到这两个参数,今天突然很想知道这两个参数的原理以及作用,因此查了下资料.真心受教了. 下面的博文是在百度空间看一位大神的,原文链接:http://hi.baidu.co ...

  7. HDU 5884 Sort ——(K叉哈夫曼树)

    这题真心比较奥义,先见这个人的博客:http://blog.csdn.net/libin66/article/details/52565484 补0的方法是使得其满足成为满K叉树,而其博客中所说的“所 ...

  8. 「Luogu P5602」小E与美食

    题目链接 戳我 \(Solution\) 这道题只需要枚举吃\(k\)个美食,最后在取前\(k\)大的美味值.对于每个算出答案后取\(max\) \(Code\) #include<bits/s ...

  9. python3.8 := and python3.7 dataclass

    代码示例 from dataclasses import field,dataclass @dataclass class People: name :str =field(init="张三 ...

  10. css三类选择器 用法 引用

    css(层叠样式表): css用法:选择符{样式属性:取值;...} css选择器的分类: ①:标签选择器,such as:p{attribute:value;},p为标签选择器的name,该页面中所 ...