19年春季第二题 PAT甲级 1157 Anniversary(25 分)

忘是亡心i 2023-07-04 14:30 91阅读 0赞

英文题目

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 NNN (≤105).
Then NNN 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 MMM(≤105). Then MMM 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:

  1. 5
  2. 372928196906118710
  3. 610481197806202213
  4. 440684198612150417
  5. 13072819571002001X
  6. 150702193604190912
  7. 6
  8. 530125197901260019
  9. 150702193604190912
  10. 220221196701020034
  11. 610481197806202213
  12. 440684198612150417
  13. 370205198709275042
  14. 1
  15. 2
  16. 3
  17. 4
  18. 5
  19. 6
  20. 7
  21. 8
  22. 9
  23. 10
  24. 11
  25. 12
  26. 13

Sample Output:

  1. 3
  2. 150702193604190912

中文题目

7-5 校庆 (25 分)

2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆,校友会收集了所有校友的身份证号。现在需要请你编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。

输入格式:

输入在第一行给出不超过 10^​5 的正整数 N,随后 N 行,每行给出一位校友的身份证号(18 位由数字和大写字母X组成的字符串)。题目保证身份证号不重复。

随后给出前来参加校庆的所有人士的信息:首先是一个不超过 10​^5 的正整数 M,随后 M 行,每行给出一位人士的身份证号。题目保证身份证号不重复。

输出格式:

首先在第一行输出参加校庆的校友的人数。然后在第二行输出最年长的校友的身份证号 —— 注意身份证第 7-14 位给出的是 yyyymmdd 格式的生日。如果没有校友来,则在第二行输出最年长的来宾的身份证号。题目保证这样的校友或来宾必是唯一的。

输入样例:

  1. 5
  2. 372928196906118710
  3. 610481197806202213
  4. 440684198612150417
  5. 13072819571002001X
  6. 150702193604190912
  7. 6
  8. 530125197901260019
  9. 150702193604190912
  10. 220221196701020034
  11. 610481197806202213
  12. 440684198612150417
  13. 370205198709275042

输出样例:

  1. 3
  2. 150702193604190912

分析

这道题没用set或者unorder set存校友名录会超时。

满分代码

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<vector>
  4. #include<string>
  5. #include<set>
  6. using namespace std;
  7. int main(){
  8. int n,m,cnt=0;
  9. cin>>n;
  10. getchar();
  11. string s,old="20190302",ans;
  12. set<string> st;
  13. for(int i=0;i<n;i++){
  14. getline(cin,s);
  15. st.insert(s);
  16. }
  17. cin>>m;
  18. getchar();
  19. for(int i=0;i<m;i++){
  20. getline(cin,s);
  21. set<string>::iterator it;
  22. if(st.find(s)!=st.end()){
  23. cnt++;
  24. }
  25. if(s.substr(6,8)<old){
  26. old=s.substr(6,8);
  27. ans=s;
  28. }
  29. }
  30. cout<<cnt<<endl;
  31. cout<<ans;
  32. return 0;
  33. }

发表评论

表情:
评论列表 (有 0 条评论,91人围观)

还没有评论,来说两句吧...

相关阅读