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

直接上题目:


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. LocalDate使用(转)

    3.Date 3.1.JDK7 Date缺点 1.所有的日期类都是可变的,因此他们都不是线程安全的,这是Java日期类最大的问题之一 2.Java的日期/时间类的定义并不一致,在java.util和j ...

  2. MySQL常见内存不足启动失败的完美解决方法

    Move to https://www.jb51.net/article/136432.htm

  3. HTML5测试题整理Ⅰ

    1.在 HTML5 中,哪个元素用于组合标题元素? 答案:<hgroup>   2.HTML5 中不再支持哪个元素? 答案:<font>,<acronym>,< ...

  4. PHP回顾(4)文件相关函数

    touch()          创建文件 (修改时间,不存在时创建) copy()            复制文件,复制过程中可以修改文件名 rename()        重命名 或  移动文件  ...

  5. python celery 异步学习

    1.运行redis 2.安装celery:pip install celery[redis] 3.vim task.py import time from celery import Celery b ...

  6. 深度学习笔记(十一)网络 Inception, Xception, MobileNet, ShuffeNet, ResNeXt, SqueezeNet, EfficientNet, MixConv

    1. Abstract 本文旨在简单介绍下各种轻量级网络,纳尼?!好吧,不限于轻量级 2. Introduction 2.1 Inception 在最初的版本 Inception/GoogleNet, ...

  7. 使用wait/notify实现生产消费模型

    public class A { private Deque<Integer> list = new LinkedList<>(); private int max = 10; ...

  8. AcWing:149. 荷马史诗(哈夫曼编码 + k叉哈夫曼树)

    追逐影子的人,自己就是影子. ——荷马 达达最近迷上了文学. 她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手的<荷马史诗>. 但是由<奥德赛>和<伊 ...

  9. java jsp基础介绍

    1         Jsp基础 1.1           Jsp介绍 JSP(全称Java Server Pages)是一种web动态网页开发技术,通过标签和指令完成用户界面开发和交互操作.它使用J ...

  10. (七)C语言之顺序结构