7-2 Anniversary

2024-03-09 05:08
文章标签 anniversary

本文主要是介绍7-2 Anniversary,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

7-2 Anniversary 

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

 

 

 

#include<iostream>
#include<map>
using namespace std;
string maxx( string a ,string b ){for( int i=6;i<=13;i++){ if( a[i] <b[i])return a;else if( a[i] > b[i] )return b;    }return a;
}
int main(void){int n;scanf("%d",&n);map<string ,int> mp;string s;for( int i=1;i<=n;i++){cin>>s;mp[s] = 1;} int m,flag=0,ans=0;scanf("%d",&m);string maxA="999999999999999999",maxG="999999999999999999";for( int i=1;i<=m;i++){cin>>s;if(  mp[s] ){ maxA=maxx( maxA,s);flag = 1;ans++;}else maxG=maxx( maxG,s);}printf("%d\n",ans);if( flag )cout<<maxA<<endl;else cout<<maxG<<endl;   return 0;
}

 

这篇关于7-2 Anniversary的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/789603

相关文章

hdu 1520 poj2342 anniversary party树形DP

每个节点要么选要么不选,和大多数选不选动归一样,来个dp[i][2],0表示不选,1表示选,那我们只要从叶子节点往根结点不断更新dp[i][0]和dp[i][1]就可以了。 状态转移方程:dp[i[[1] += dp[j][0]                       (当前选了,子节点必定不能选,然后累加)                        dp[i][0] += max

POJ - 1020 Anniversary Cake

题意:有一块边长为BoxSize的正方形的大蛋糕,现在给出n块不同尺寸的正方形的小蛋糕的边长,问是否能把大蛋糕按恰好切割为这n块小蛋糕,要求每块小蛋糕必须为整块。 思路:有技巧性的DFS,这里有一篇写的很好的:点击打开链接 #include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using

【Canvas与艺术】绘制铜质蓝底五周年(Five Years Anniversary)徽章

【关键点】 利用二次贝塞尔曲线生成环形波纹轮廓。 【成果图】 【代码】 <!DOCTYPE html><html lang="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><head><title>铜质五周年徽章</title><style type="text/css

13. Anniversary

题目链接:Anniversary 给出 m , l , r , k m,l,r,k m,l,r,k,让你在斐波那契数列的第 l l l 到第 r r r 项之间选出 k k k 个,最大化这 k k k 个数的 gcd,对 m m m 取模后输出。 首先需要知道一个重要结论: gcd ⁡ ( F [ a ] , F [ b ] ) = F [ gcd ⁡ ( a , b ) ] \

Anniversary party求助

 http://poj.org/problem?id=2342 /// 为什么有错 #include<iostream> #include<string> #define max(x,y) (x>y?x:y) using namespace std; int vis[6010],dp[6010][2],n,father[6010]; void dfs(int node) {  in

PAT(甲级)2019年春季考试7-2 Anniversary (25 分)

7-2 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. N

hdu 1520 Anniversary party(基本树形DP)

1、http://acm.hdu.edu.cn/showproblem.php?pid=1520 2、题目大意: 有n个员工,每个员工都有一个rating值,给出员工之间的上下级的关系,要求是有直接上下级关系的员工不能同时出席,现在要求的是选择哪些员工出席,会使得他们的rating之和最大 定义dp[i][1]表示i员工出席时的最大值,dp[i][0]表示i员工不出席时的最大值 dp[i]

树形DP 加分二叉树 and HDU 1520 Anniversary party

题目描述 设一个n个节点的二叉树tree的中序遍历为(l,2,3,…,n),其中数字1,2,3,…,n为节点编号。每个节点都有一个分数(均为正整数),记第j个节点的分数为di,tree及它的每个子树都有一个加分,任一棵子树subtree(也包含tree本身)的加分计算方法如下: subtree的左子树的加分× subtree的右子树的加分+subtree的根的分数 若某个子树为主,规定其加