记录下,2020pat春季考试题目及答案

本文记录了2020年PAT春季考试的四道题目,包括7-1 Prime Day、7-2 The Judger、7-3 Safari Park和7-4 Replacement Selection,每道题目都附带了相应的代码实现。
摘要由CSDN通过智能技术生成

题目在这里,可以超市购买,之后应该会放到题库里边

7-1 Prime Day (20分)

  • 代码:
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
string date;
bool isPrime(int num){
   
    if(num<=1) return false;
    for(int i=2;i*i<=num;++i){
   
        if(num%i==0) return false;
    }
    return true;
}
int getNum(string str){
   
    int len=str.length(),ans=0;
    for(int i=0;i<len;++i){
   
        ans=ans*10+(str[i]-'0');
    }
    return ans;
}
int main(){
   
    cin>>date;
    int flag=1;
    while(1){
   
        printf("%s ",date.c_str());
        int temp=getNum(date);
        if(isPrime(temp)==true) printf("Yes\n");
        else{
   
            printf("No\n");
            flag=0;
        }
        if(date.length()==1) break;
        date=date.substr(1,date.length());
    }
    if(flag==1) printf("All Prime!\n");
    return 0;
}

7-2 The Judger (25分)

  • 代码
#include<stdio.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<unordered_set>
using namespace std;
const int Maxn=100010;
int N,M;
int isExisted[Maxn],st_differences[Maxn];
int isOut[15];
vector<int> players[15],
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值