- 博客(306)
- 收藏
- 关注
原创 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
201
原创 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
126
原创 排序(二)
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
126
原创 排序(一)
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
524
1
原创 算法笔记(二分法)
在严格递增序列中查找给定的数x#include<iostream>using namespace std;int binary(int a[],int l,int r,int x){//二分法区间是左闭右闭的区间 int mid; while(l<=r)//当l>r时结束 { mid=l+(r-l)/2; if(a[mid]==x)return mid; else if(a[mid]>x)r=mid-1; else l=mid+1; }
2022-02-22 22:01:45
213
原创 3375. 成绩排序
题目链接https://www.acwing.com/problem/content/3378/#include<iostream>#include<algorithm>using namespace std;struct Student{ string name;//名字 int score;//成绩 int id;//学号 }stu[10010];//升序 bool cmp1(Student a,Student b){ if(a.score.
2022-02-15 22:35:20
391
原创 838. 堆排序
题目来源https://www.acwing.com/problem/content/840///如何手写一个堆?完全二叉树 5个操作//1. 插入一个数 heap[ ++ size] = x; up(size);//2. 求集合中的最小值 heap[1]//3. 删除最小值 heap[1] = heap[size]; size -- ;down(1);//4. 删除任意一个元素 heap[k] = heap[size]; size -- ;up(.
2022-02-14 17:40:30
122
原创 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
251
原创 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
414
原创 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
223
原创 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
7514
原创 869. 试除法求约数
题目链接#include<iostream>#include<algorithm>#include<vector>using namespace std;vector<int> divisors(int n){ vector<int>res; for(int i=1;i<=n/i;i++)//从小到大枚举较小的那个约数即可 { if(n%i==0)//如果i是n的一个约数
2022-02-09 15:19:27
364
原创 828. 模拟栈
#include<iostream>using namespace std;const int maxn=1e6+10;int st[maxn]; int top=-1;//表示栈为空 int main(){ int n; cin>>n; for(int i=0;i<n;i++) { string s; cin>>s; if(s=="push"){ int x; cin>>x; st[++top]=x;.
2022-02-07 19:22:51
318
原创 799. 最长连续不重复子序列
#include<iostream>using namespace std;const int maxn=1e5+10;int a[maxn],b[maxn];int main(){ //k是最长连续不重复子序列元素的个数 int n,k=0; cin>>n; for(int i=0,j=0;j<n;j++) { cin>>a[j]; b[a[j]]++; while(b[a[j]]>1){ b[a[i]]-=1;.
2022-02-07 17:42:35
422
原创 C++中的auto用法
for(auto count : counts)意思是将 counts 容器中的每一个元素从前往后枚举出来,并用 count 来表示#include<iostream>#include<vector>using namespace std;int main() { int a[] = { 1,2,3,5,2,0 }; vector<int>counts(a,a+6); for (auto count : counts)
2022-01-30 19:23:39
755
原创 1015 德才论 (25 分)
题目来源https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312#include<iostream>#include<cstring>#include<algorithm> using namespace std;struct stud{ char id[10]; //准考证号 int de,cai,sum; //德分,才分,总分 .
2022-01-28 19:19:15
91
原创 1031 查验身份证 (15 分)
题目来源:https://pintia.cn/problem-sets/994805260223102976/problems/994805290334011392分析:isTrue函数判断身份证号是否正常,如果不正常返回false判断每一个给出的身份证号如果不正常,就输出这个身份证号,并且置flag=1表示有不正常的号码如果所有的号码都是正常,即flag依旧等于0,则输出All passed在isTrue函数中,先判断前17位是否是数字如果不是,直接return false如果是,
2022-01-23 20:47:45
288
原创 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
5276
原创 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
200
原创 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
93
原创 1010 一元多项式求导 (25 分)
题目来源#include<iostream> using namespace std;int main(){ int a,b; int flag=0;//flag用来判断是否有输出 while(cin>>a>>b) { if(b!=0) { if(flag==1) { cout<<" "; } cout<<a*b<<" "<<b-1; flag=1; }
2022-01-21 11:39:35
94
原创 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
95
原创 790. 数的三次方根
给定一个浮点数n,求它的三次方根。输入格式共一行,包含一个浮点数 n。输出格式共一行,包含一个浮点数,表示问题的解。注意,结果保留 6 位小数。数据范围−10000≤n≤10000输入样例:1000.00输出样例:10.000000#include <iostream>using namespace std;int main() { double x; cin >> x; // 确定边界值 double l .
2022-01-20 21:24:41
4219
原创 789. 数的范围
给定一个按照升序排列的长度为n的整数数组,以及q个查询。对于每个查询,返回一个元素k的起始位置和终止位置(位置从0开始计数)。如果数组中不存在该元素,则返回-1 -1。输入格式第一行包含整数 n 和 q,表示数组长度和询问个数。第二行包含 n 个整数(均在 1∼10000 范围内),表示完整数组。接下来 q 行,每行包含一个整数 k,表示一个询问元素。输出格式共 q 行,每行包含两个整数,表示所求元素的起始位置和终止位置。如果数组中不存在该元素,则返回 -...
2022-01-20 21:13:40
99
原创 788. 逆序对的数量
给定一个长度为 nn 的整数数列,请你计算数列中的逆序对的数量。逆序对的定义如下:对于数列的第 i个和第 j 个元素,如果满足 i<j 且 a[i]>a[j]],则其为一个逆序对;否则不是。输入格式第一行包含整数 n,表示数列的长度。第二行包含 n 个整数,表示整个数列。输出格式输出一个整数,表示逆序对的个数。数据范围1≤n≤100000,数列中的元素的取值范围 [1,10^9]。输入样例:62 3 4 5 6 1输出样例:5方法一、归并排序#
2022-01-20 20:08:18
106
转载 232. 用栈实现队列
请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):实现 MyQueue 类:void push(int x) 将元素 x 推到队列的末尾int pop() 从队列的开头移除并返回元素int peek() 返回队列开头的元素boolean empty() 如果队列为空,返回 true ;否则,返回 false说明:你只能使用标准的栈操作 —— 也就是只有push to top,peek/pop from top,s...
2022-01-20 17:18:33
87
原创 20. 有效的括号
给定一个只包括 '(',')','{','}','[',']'的字符串 s ,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。示例 1:输入:s = "()"输出:true示例2:输入:s = "()[]{}"输出:true示例3:输入:s = "(]"输出:false示例4:输入:s = "([)]"输出:false示例5:输入:s = "{[]}"输出:true提示:1 <...
2022-01-20 17:10:17
203
原创 1012 数字分类 (20 分)
题目链接思路:1、数组count[5]用来存放五类数字的个数,初值为02、数组ans[5]用来存放五类数字的输出结果,初值为03、最后一个输出后面不能有空格#include<iostream>using namespace std;const int maxn=10010;int count[5]={0},ans[5]={0};int main(){ int n; cin>>n; int t; for(int i=0;i<n;i++)
2022-01-19 15:41:51
219
原创 1008 数组元素循环右移问题 (20 分)
题目链接思路一:1、由于没有给出m的最大值,因此不能直接认为m<n,需要令m=m%n来保证m<n2、输出序列从n-m号到n-1号元素后再继续输出0号元素到n-m-1号元素即可注意:1、处理最后一个数后不输出空格,使用count变量记录已经输出的数的个数,只要count没有达到啊n就输出空格#include<iostream>using namespace std;const int maxn=10010;int a[maxn];int main()
2022-01-19 15:08:49
1786
原创 83. 删除排序链表中的重复元素
存在一个按升序排列的链表,给你这个链表的头节点 head ,请你删除所有重复的元素,使每个元素 只出现一次 。返回同样按升序排列的结果链表。示例 1:输入:head = [1,1,2]输出:[1,2]示例 2:输入:head = [1,1,2,3,3]输出:[1,2,3]提示:链表中节点数目在范围 [0, 300] 内-100 <= Node.val <= 100题目数据保证链表已经按升序排列思路:不断判断当前节点的下一个节点的val是否与当前节点的va.
2022-01-19 11:53:50
183
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人