20190302春季PAT考试甲级答案
7-1 Sexy Primes (20 分)
Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)

Now given an integer, you are supposed to tell if it is a sexy prime.

Input Specification:
Each input file contains one test case. Each case gives a positive integer N (≤108​​ ).

Output Specification:
For each case, print in a line Yes if N is a sexy prime, then print in the next line the other sexy prime paired with N (if the answer is not unique, output the smaller number). Or if N is not a sexy prime, print No instead, then print in the next line the smallest sexy prime which is larger than N.

Sample Input 1:
47
Sample Output 1:
Yes
41

Sample Input 2:
21
Sample Output 2:
No
23
分析:此题难度不大,考察点是利用循环进行素数的判断。
首先明白Sexy primes的定义,如果N为素数,且N+6或者N-6也为素数,则N为Sexy prime。
输出要求:
1.如果N是素数,且N+6也为素数,则N为Sexy prime,输出Yes(换行)输出N。
2.或者N是素数,且N-6也为素数,则N为Sexy prime,输出No(换行)输出N-6。
3.如果N不是Sexy prime,则输出比N大的Sexy prime里面最小的那个数字。

#include <stdio.h>
int IsPrime(int N)
{int i,flag=1;for(i=2;i<N;i++){if(N%i==0){flag=0;break;}}return flag;
}
int main()
{int N,x;scanf("%d",&N);if(IsPrime(N)&&IsPrime(N+6)){printf("Yes\n%d",N);}else if(IsPrime(N)&&IsPrime(N-6)){printf("Yes\n%d",N-6);}else {printf("No\n");for(x=N;IsPrime(x)==0;x++){}printf("%d",x); }return 0;
}

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. 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
分析:浙江大学校庆,统计了校友会的N位贵宾,还有所有实际到场的M位来宾,每位宾客均有自己的18位ID号。输入
输入要求:
1.输入N。
2.输入每位贵宾的ID。
3.输入M.。
4.输入每位来宾的ID。
输出要求:
1.输出在所有来宾中的贵宾总数。
2.输出到场的贵宾中最年长的那位的ID,如果没有贵宾到场,则输出所有来宾中最年长的那位的ID。

#include<stdio.h>
//构造结构体
struct Per
{char ID[19];   } ;struct Per al[100000],gu[100000];//al代表alumni,gu代表gust int main (){int N,M,i,j,s,sum=0,flag;int old[100000];scanf("%d",&N);//根据输入的N的个数来确定输入的al的ID for(i=0;i<N;i++){for(j=0;j<19;j++)scanf("%c",&al[i].ID[j]);}//根据输入的M的个数来确定输入的gu的ID scanf("%d",&M);for(i=0;i<M;i++){for(j=0;j<19;j++)scanf("%c",&gu[i].ID[j]);}//将al与gu逐项对比,来确认实际到场的al的总数sum for(i=0;i<N;i++){for(j=0;j<M;j++){for(s=0;s<19;s++){if(al[i].ID[s]!=gu[j].ID[s])break;else if(s==18){old[sum]=i;sum++;} }}}printf("%d",sum);//如果有实际到场的al,则确定这些到场的al中最老的那一位 if(sum!=0){flag=old[0];for(i=1;i<sum;i++){j=old[i];for(s=6;s<14;s++){if(al[flag].ID[s]>al[j].ID[s]){flag=j;break;}}}for(j=0;j<19;j++)printf("%c",al[flag].ID[j]);}//如果没有实际到场的al,则确定这些到场的gu中最老的那一位 else if(sum==0){flag=0;for(i=1;i<M;i++){for(s=6;s<14;s++){if(gu[flag].ID[s]>gu[i].ID[s]){flag=i;break;}}}for(j=0;j<19;j++)printf("%c",gu[flag].ID[j]);}return 0;}

2019春季PAT考试甲级答案相关推荐

  1. PAT(乙级)2019年冬季考试【答案+题解】

    7-1 2019数列 (15分) 7-2 老鼠爱大米 (20分) 7-3 String复读机 (20分) 7-4 擅长C (20分) 7-5 区块反转 (25分) 7-1 2019数列 (15分) 把 ...

  2. 2019秋季PAT甲级考试总结:努力+策略+运气

    鉴于这两天有很多网友联系我问这次考试的题解,所以我干脆就花点时间把C++题解整理出来了,见文末 经过一两个月的备战PAT,在今天终于画上了一个圆满的句号,取得了满分的成绩. 我是在南京的金陵科技学院考 ...

  3. 2019秋季PAT甲级考试心得

    第一道题一共四个测试点,做了一个小时,有两个测试点没过,得了12/20分 做题的时候遇到一个问题,就是include<math.h>之后,使用pow(10,n)计算报错具有多个定义之类的( ...

  4. 2021年春季PAT甲级考试

    作为一个绩点不高.牌子不硬的退役ACMer,去年冬天在nvpy的鼓励下,决定先试试PAT为考研做准备,于是认认真真把所有20分的题目过了一遍.放寒假以后,就开始练习所有25分的题目,并且每道题做完都总 ...

  5. PAT学习资料汇总(PAT甲级、PAT顶级、PAT考试经验)

    二.PAT甲级 PAT甲级真题目录(按题型整理) PAT甲级真题目录(按题型整理)_love music.的博客-CSDN博客_pat甲级真题 PAT甲[所有题目+解析+代码示例+总结]附带所有历年整 ...

  6. 2019年9月 第一次参加PAT考试体验及题解

    2020-12-16 更新: 时间过得好快,大四上学期已经上完了. 楼主现在保研本校(北京邮电大学)计算机科学与技术(计算机学硕),计算机网络+机器学习方向,现在国内经济不景气,我在学校深深体会到了学 ...

  7. PAT-2022年春季考试 - 甲级题解

    试卷在此 7-1 Simple Lie Detection (20 分) 作者 陈越 单位 浙江大学 代码长度限制 16 KB 时间限制 400 ms 内存限制 64 MB Lie detection ...

  8. 2019秋季PAT甲级_C++题解

    2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...

  9. 计算机excl知识题,2019职称计算机考试Excel模拟题及答案(1.18)

    [导语]2019年职称计算机考试备考正在进行中,为了方便考生及时有效的备考,那么,无忧考网为您精心整理了2019职称计算机考试Excel模拟题及答案(1.18),把握机会抓紧练习吧.如想获取更多职称计 ...

最新文章

  1. 线性规划、梯度下降、正规方程组——斯坦福ML公开课笔记1-2
  2. ITK:使用地标将图像注册到另一个图像
  3. 5g空分复用技术_5G十大关键技术之三的空分复用
  4. 修改mongodb最大查询数_WebFlux系列(十二)MongoDB应用,新增、修改、查询、删除
  5. 小型数据库_如果您从事“小型科学”工作,那么您是否正在利用数据存储库?
  6. php java c_当PHP、Java、C、C++ 这几种编程语言变成汽车是什么样的场景?
  7. 苹果iOS 13正式版推送:深色模式来了 速度再次提升!
  8. 11、web端主要应用在哪些领域?
  9. SAP MM 采购单据中的’Origin Accept’选项会影响Inbound Delivery创建操作方式
  10. MFC学习(实时更新)
  11. CIC滤波器的设计与仿真
  12. 基于蒙特卡洛的大规模电动汽车充电行为分析(Matlab代码实现)
  13. matlab计算器设计流程图_matlab计算器设计
  14. Python笔记:数据切片
  15. 51单片机数字时钟套件 DIY散件
  16. Dev-C++5.11游戏创作之火柴人跑酷
  17. 计算机应用1.2版,201303《计算机应用基础》在线作1-2.doc
  18. 单节点Rancher离线安装的关键一步
  19. java 单链表一元多项式_java单链表实现一元多项式加法和乘法运算
  20. 一类用 LCT 维护信息的题目

热门文章

  1. Tuesday 5th January 2010
  2. 基于java自动售货机 课程设计_JAVA-案例-自动售货机.pdf
  3. CentOS 7禁用THP
  4. 靠物管服务撑起半壁江山,华润万象生活还能笑多久
  5. 仿咔叽分享页层级滑动效果
  6. 【PyCharm良心插件推荐】如何让自己的PyCharm独具一格?
  7. 从迅雷下载比一比想到的
  8. C/C++main函数返回值以及return 0的作用
  9. 超好用!让你秒变声优博主
  10. [转载]蝈蝈学拳笔记-7-9-吴式太极-玉女穿梭等