2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆,校友会收集了所有校友的身份证号。现在需要请你编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。
输入格式:
输入在第一行给出不超过 105 的正整数 N,随后 N 行,每行给出一位校友的身份证号(18 位由数字和大写字母X组成的字符串)。题目保证身份证号不重复。
随后给出前来参加校庆的所有人士的信息:首先是一个不超过 105 的正整数 M,随后 M 行,每行给出一位人士的身份证号。题目保证身份证号不重复。
输出格式:
首先在第一行输出参加校庆的校友的人数。然后在第二行输出最年长的校友的身份证号 —— 注意身份证第 7-14 位给出的是 yyyymmdd
格式的生日。如果没有校友来,则在第二行输出最年长的来宾的身份证号。题目保证这样的校友或来宾必是唯一的。
输入样例:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
输出样例:
3
150702193604190912
代码长度限制
16 KB
时间限制
800 ms
内存限制
64 MB
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int compare1(const void* a,const void* b){
return strcmp(a,b);
}
void* compare2(const void* a,const void* b){
return strcmp(a,b);
}
int main(){
int N,M;
char ch1[100001][19],ch2[19];
scanf("%d",&N);
for(int i=0;i<N;i++){
getchar();
scanf("%s",ch1[i]);
}
qsort(ch1,N,sizeof(char)*19,compare1);
scanf("%d",&M);
int flag=0,p=0,q=0,count=0;
char str1[19],str2[19];
for(int i=0;i<M;i++){
getchar();
scanf("%s",ch2);
if(bsearch(ch2,ch1,N,sizeof(char)*19,compare2)){
count++;
flag=1;
if(p==0){
strcpy(str1,ch2);
p=1;
}else{
if(strncmp(ch2+6,str1+6,8)<0){
strcpy(str1,ch2);
}
}
}else{
if(q==0){
strcpy(str2,ch2);
q=1;
}else{
if(strncmp(ch2+6,str2+6,8)<0){
strcpy(str2,ch2);
}
}
}
}
if(flag==1){
printf("%d\n",count);
printf("%s\n",str1);
}else{
printf("%d\n",count);
printf("%s\n",str2);
}
}