![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
PAT甲级试题
PAT考试
Leo就是LEO
命、是失败者的借口。运、是成功者的谦词。
展开
-
PAT甲级分类
入门模拟1042 Shuffling Machine (20 分)1046 Shortest Distance (20 分)1065 A+B and C (64bit) (20 分)1002 A+B for Polynomials (25 分)1009 Product of Polynomials (25 分)查找元素原创 2022-02-27 15:49:20 · 171 阅读 · 0 评论 -
1042 Shuffling Machine (20 分)
#include<iostream>using namespace std;int main(){ char mp[5]={'S','H','C','D','J'};//牌的编号与花色的对应关系 int start[55],end[55],next[55];//next数组存放每个位置上的牌在操作后的位置 int k;//输入转换次数 cin>>k; for(int i=1;i<=54;i++)start[i]=i;//初始化牌的编号 for(int .原创 2022-02-27 14:57:41 · 96 阅读 · 0 评论 -
排序(二)
1071. Speech Patterns (25)-PAT甲级真题(map应用)#include <iostream>#include <map>#include <cctype>using namespace std;int main() { string s, t; getline(cin, s);//读入一长串的带空格的字符串 map<string, int> m; for(int i = 0; i &l原创 2022-02-25 16:22:58 · 102 阅读 · 0 评论 -
排序(一)
1001. A+B Format (20)-PAT甲级真题#include<iostream>using namespace std;int main(){ int a,b; cin>>a>>b; int sum=a+b; if(sum<0) { cout<<"-"; sum=-sum; } string s=to_string(sum);//用to_string函数把数字转换成字符串 string res; int原创 2022-02-24 17:09:22 · 467 阅读 · 1 评论 -
1015 Reversible Primes (20 分)
https://pintia.cn/problem-sets/994805342720868352/problems/994805495863296000#include<iostream>#include<algorithm>#include<math.h>using namespace std;bool is_prime(int n)//判断素数 { if (n <2) { return false; } .原创 2022-02-12 20:13:12 · 207 阅读 · 0 评论 -
1019 General Palindromic Number (20 分)
题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984#include<iostream>using namespace std;bool judge(int a[],int n){ for(int i=0;i<=n/2;i++) { if(a[i]!=a[n-1-i]) { return false; } } return true; .原创 2022-02-12 20:03:52 · 373 阅读 · 0 评论 -
1050 String Subtraction (20 分)
题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152#include<iostream>using namespace std;string s1,s2;int a[200]; //利用桶来标记出现的字符int main(){ getline(cin,s1); getline(cin,s2); int len1=s1.length();原创 2022-02-11 22:01:45 · 191 阅读 · 0 评论 -
1035 Password (20 分)
题目在此https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520#include <iostream>#include <vector>using namespace std;int main() { int n; cin>>n; vector<string> v; for(int i = 0; i < n;原创 2022-02-11 21:39:09 · 7404 阅读 · 0 评论 -
1036 Boys vs Girls (25 分)
题目链接#include <iostream>using namespace std;int main() { int n; scanf("%d", &n); string female, male; int femalescore = -1, malescore = 101; for(int i = 0; i < n; i++) { string name, sex, num; int score;原创 2022-01-22 15:43:43 · 5186 阅读 · 0 评论 -
1006 Sign In and Sign Out (25 分)
题目来源#include<iostream>#include<climits>using namespace std;int main(){ int n,min=INT_MAX,max=INT_MIN; cin>>n; string unlock,lock; for(int i=0;i<n;i++) { strint t; cin>>t;//名字 int s1,f1,m1,s2,f2,m2;//进入时间和出去时间原创 2022-01-22 15:27:35 · 176 阅读 · 0 评论 -
1011 World Cup Betting (20 分)
题目链接题目大意:给出三场比赛以及每场比赛的W、T、L的赔率,选取每一场比赛中赔率最大的三个数a b c,先输出三行各自选择的是W、T、L中的哪一个,然后根据计算公式 (a * b * c * 0.65 – 1) * 2 得出最大收益~分析:以三个数一组的形式读取,读取完一组后输出最大值代表的字母,然后同时ans累乘该最大值,最后根据公式输出结果~#include<iostream>using namespace std;int main() { char c[3]={'W原创 2022-01-22 15:11:51 · 70 阅读 · 0 评论 -
1046 Shortest Distance (20 分)
The task is really simple: givenNexits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.题目来源#include<iostream>#include<vector>using namespace std;int main(){ int n; c..原创 2022-01-21 11:15:07 · 63 阅读 · 0 评论 -
1060 Are They Equal (25 分)
题目来源#include<iostream>#include<string>using namespace std;int n;//有效位数string deal(string s,int &e){ int k=0;//s的下标 while(s.length()>0&&s[0]=='0') { s.erase(s.begin());//去掉前导0 } if(s[0]=='.')//去掉前导0后是小数点,说明s是小于1的小原创 2022-01-17 15:25:09 · 65 阅读 · 0 评论 -
算法笔记C++中STL的vector
1、vectorvector是一个变长数组,使用vector时需要添加#include<vector>头文件。2、push_back()push_back(x)就是在vector后面添加一个元素xpop_back()就是删除vector的尾元素size()是用来获得vector中元素的个数#include<iostream>#include<vector>using namespace std;int main(){ vector<原创 2022-01-17 14:23:31 · 196 阅读 · 0 评论 -
1059 Prime Factors (25 分)
题目链接#include<iostream>#include <vector>using namespace std;vector<int> prime(50000, 1);//声明一个初始大小为50000且初始值都为1的向量int main() { for(int i = 2; i * i < 50000; i++) for(int j = 2; j * i < 50000; j++) prime原创 2022-01-17 10:43:00 · 136 阅读 · 0 评论 -
1013 数素数 (20 分)
令Pi表示第i个素数。现任给两个正整数M≤N≤104,请输出PM到PN的所有素数。输入描述:输入在一行中给出M和N,其间以空格分隔。输出描述:输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。输入例子:5 27输出例子:11 13 17 19 23 29 31 37 41 4347 53 59 61 67 71 73 79 83 8997 101 103#include<iostream>usi...原创 2022-01-16 18:31:40 · 79 阅读 · 0 评论 -
求100以内的所有素数(筛选法)
#include<iostream>using namespace std;const int maxn=101;int prime[maxn],pnum=0;//prime数组存放所有素数,pnum为素数个数bool p[maxn]={false};//p[i]为false表示i是素数void find_prime(){ for(int i=2;i<maxn;i++) { if(p[i]==false) { prime[pnum++]=i;//把素数i存.原创 2022-01-16 18:20:34 · 282 阅读 · 0 评论 -
算法笔记-分数的表示和化简
1、使用结构体来存储分数的分子和分母2、对分数指定规则 1、使分母为非负数,如果分数为负,则令分子为负数即可 2、如果分数为零,则规定分子为零,分母为1 3、分子和分母没有除1以外的公约数3、分数的化简 1、若分母为负数,则令分子和分母都变为相反数 2、若分子为零,则令分母为1 3、约分,求出分子绝对值与分母绝对值的最大公约数,然后令分子分母同时除以公约数#include<iostream>using nam...原创 2022-01-16 16:55:30 · 974 阅读 · 0 评论 -
1069 The Black Hole of Numbers (20 分)
#include <iostream>#include <algorithm>using namespace std; bool cmp(int a,int b){ return a>b;}int main(){ int n,a[4]={0},b,c,t; cin>>n; t=n; do{ a[0]=t/1000;//千位 a[1]=t%1000/100;//百位 a[2]=t%1000%100/10;//十位 ...原创 2022-01-16 16:14:22 · 46 阅读 · 0 评论 -
1136 A Delayed Palindrome (20 分)
1136 A Delayed Palindrome (20 分)#include<iostream>#include<algorithm>using namespace std;string rev(string s)//逆转函数 { reverse(s.begin(),s.end()); return s;}string add(string s1,string s2)//加法运算 { string s=s1; int t=0;//进位 for(i.原创 2021-02-24 22:29:30 · 74 阅读 · 0 评论 -
算法基础课(高精度)
高精度加法#include<iostream>#include<vector>using namespace std;const int maxn=1e6+10;//C=A+B vector<int>add(vector<int>&A,vector<int>&B){ vector<int>C; int t=0;//进位 for(int i=0;i<A.size()||i<B.size原创 2021-02-23 19:39:07 · 315 阅读 · 0 评论 -
算法基础课(排序)
快排#include<iostream>using namespace std;const int maxn=10010;int a[maxn];void quick_sort(int a[],int l,int r){ if(l>=r)return ;//判断边界 int x=a[l],i=l-1,j=r+1;//双指针 while(i<j) { do i++;while(a[i]<x); do j--;while(a[j]>x);原创 2021-02-22 22:16:44 · 104 阅读 · 0 评论 -
1025 PAT Ranking (25 分)
1025 PAT Ranking (25 分)#include<iostream>#include<algorithm>#include<cstring>using namespace std; struct student{ char sno[15]; int score;//分数 int location_num;//考场号 int local_rank;//考场排名 //总排名即是排序后的顺序}stu[30010];//k<=30原创 2021-02-22 18:12:22 · 59 阅读 · 0 评论 -
1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分)#include<iostream>#include<cstring>#include<algorithm> using namespace std;struct student{ char id[10]; //准考证号 int de,cai,sum; //德分,才分,总分 int flag; //考生类别:第1类~第5类}stu[100010];bool cmp(st原创 2021-02-22 17:35:30 · 142 阅读 · 1 评论 -
1058 A+B in Hogwarts (20 分)
1058 A+B in Hogwarts (20 分)#include<iostream>using namespace std;int main(){ int a[3],b[3],c[3]; scanf("%d.%d.%d %d.%d.%d",&a[0],&a[1],&a[2],&b[0],&b[1],&b[2]); int carry=0;//进位 c[2]=(a[2]+b[2])%29; carry=(a[2]+b[2原创 2021-02-22 16:00:03 · 75 阅读 · 0 评论 -
1046 Shortest Distance (20 分)
1046 Shortest Distance (20 分)#include <iostream>#include <vector>using namespace std;int main() { int n; cin>>n; vector<int> dis(n + 1); int sum = 0, left, right; int cnt;//cnt个查询 for(int i = 1; i <=原创 2021-02-21 20:00:40 · 49 阅读 · 0 评论 -
1065 A+B and C (64bit) (20 分)
1065 A+B and C (64bit) (20 分)#include <cstdio>using namespace std;int main() { int n; scanf("%d", &n); for(int i = 0; i < n; i++) { long long a, b, c; scanf("%lld %lld %lld", &a, &b, &c); lo原创 2021-02-21 19:39:34 · 90 阅读 · 0 评论 -
1019 General Palindromic Number (20 分)
1019 General Palindromic Number (20 分)#include<iostream>#include<vector>using namespace std;vector<int>num;bool check()//判断回文数 { for(int i=0,j=num.size()-1;i<j;i++,j--) { if(num[i]!=num[j]) { return false; } } r原创 2021-02-20 19:45:45 · 60 阅读 · 0 评论 -
1051 Pop Sequence (25 分)
1051 Pop Sequence (25 分)参考来源:1051. Pop Sequence (25)-PAT甲级真题(栈模拟)#include <iostream>#include <stack>#include <vector>using namespace std;int main() { int m, n, k; cin>>m>>n>>k; for(int i = 0; i <原创 2021-02-20 17:34:21 · 84 阅读 · 0 评论 -
《算法笔记》散列
给出N个整数,在给出M个数,问这M个数中的每个数是否在N个数中出现过例如:N=5,M=3N={8,3,7,6,2},M={7,4,2}后者中只有7和2在N个整数中出现过。思想:用空间换时间的方法。#include <iostream>using namespace std;const int maxn=10010;bool hashTable[maxn]={false};//表示正整数没有在N个数中出现过 int main() { int n,m,x; ci原创 2021-02-17 21:21:58 · 57 阅读 · 0 评论 -
1027 Colors in Mars (20 分)
1027 Colors in Mars (20 分)题目大意:给三个十进制的数,把它们转换为十三进制的数输出。要求在前面加上一个"#"号。#include <iostream>using namespace std;int main() { char c[14] = {"0123456789ABC"}; cout<<"#"; for(int i = 0; i < 3; i++) { int num; c原创 2021-02-17 18:10:57 · 87 阅读 · 0 评论 -
1015 Reversible Primes (20 分)
1015 Reversible Primes (20 分)#include<iostream>#include<algorithm>#include<math.h>using namespace std;bool is_prime(int n)//判断素数 { if (n <2) { return false; } for (int i = 2; i <=sqrt(n); i ++ ) {原创 2021-02-17 17:59:29 · 57 阅读 · 0 评论 -
1024 Palindromic Number (25 分)
题目链接:1024 Palindromic Number (25 分)#include <iostream>#include <vector>using namespace std;bool check(vector<int>& num)//判断是否是回文数 { for (int i = 0, j = num.size() - 1; i < j; i ++, j -- ) if (num[i] != num[j])原创 2021-02-17 16:39:14 · 86 阅读 · 0 评论 -
1023 Have Fun with Numbers (20 分)
自测-4 Have Fun with Numbers (20分)题目大意:对于这种英文题,小编肯定也是读不懂,谷歌翻译的,题目的大意就是,有那么一种数,将其加倍(乘以2)后的数字仍然是原数字组合而成,现在就是要让你从控制台输入一个数字,然后你需要判断它是否满足上述条件,满足:输出Yes+加倍后的数字,不满足:输出No+加倍后的数字。...原创 2020-02-28 10:11:26 · 259 阅读 · 0 评论 -
1009 Product of Polynomials (25 分)
题目链接:1009 Product of Polynomials (25 分)#include <iostream>using namespace std;const int maxn=10010; double a[maxn],b[maxn],c[maxn+maxn];//第一个多项式计入到a数组中 void input(double a[])//用函数输入两个多项式 { int k; cin>>k; for(int i=0;i<k;i++)原创 2021-02-17 16:07:52 · 79 阅读 · 0 评论 -
冒泡排序
输入n个数,进行n-1趟排序,每个数都与他们下一个数进行比较#include<iostream>using namespace std;const int maxn=10010;int a[maxn];int main(){ int n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; } for(int i=1;i<n;i++)//进行n-1趟 { for(int j=0;j<原创 2021-02-15 16:52:48 · 55 阅读 · 0 评论 -
PAT甲级英语词汇(一)
1001 A+B Format (20 分)】format 格式calculate 计算commas 逗号Input Specification 输入格式a pair of 一对Sample Input 输入样例1002 A+B for Polynomials (25 分)Polynomials 多项式exponents 指数coefficients 系数accurate 准确的respectively 分别1003 Emergency (25 分)e原创 2021-02-15 12:30:58 · 180 阅读 · 0 评论 -
PAT甲级题型分类(高精度)
1002 A+B for Polynomials (25 分)原创 2021-02-08 01:04:09 · 591 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)
题目链接:1002 A+B for Polynomials (25 分)题目大意:给出格式相同的两行,第一行的第一个整数K表示多项式A的非零项的个数,后面的每两个数表示一项,分别是该项的指数和系数;第二行则表示多项式B的相关项的个数。求A+B,即多项式求和。输出格式同输入格式,第一个K仍是A+B的非零项的个数。#include <iostream>using namespace std;int main() { float c[1001] = {0};//设立C数组,表示原创 2021-02-08 01:03:19 · 483 阅读 · 0 评论 -
差分
797. 差分思路:参考思路思路2:参考思路原创 2021-02-07 22:38:00 · 68 阅读 · 0 评论