![](https://img-blog.csdnimg.cn/20190927151026427.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
基础算法
合并链表
caesaryun
这个作者很懒,什么都没留下…
展开
-
PAT 1017 A除以B
了解清楚除法过程即可。#include <iostream>#include <cstring>using namespace std; int main(){ int b; string a; cin>>a>>b; int q,r=0; bool isgo = true; int len = a.size(); for(int i=0;i<len;i++) { q = .原创 2022-02-12 13:00:21 · 418 阅读 · 0 评论 -
PAT 1016 部分A+B
#include <iostream>#include <cstring>#include <sstream>using namespace std; int main(){ int da,db; string a,b; while(cin>>a>>da>>b>>db) { char c = getchar(); if(c=='\n') break; } string pa.原创 2022-02-09 19:44:25 · 430 阅读 · 0 评论 -
PAT 1015 德才论(满分版)
1.出现超时的情况,使用了一个快速排序,一个冒泡排序,来尽力下降时间,不过还是会超,当然这种情况是一种比较常规的思路。不过很明显这个题,应该是要使用其他的方法,不然超时确实难以改善,我想着全部用快排解决,但错误增加,时间没减,只能选择放弃快排解决一切。先给出这个常规思路但超时的代码。待完善后再附上之后代码。#include <iostream>#include <cstring>using namespace std;struct stu{ int no.原创 2022-01-21 17:46:48 · 1454 阅读 · 0 评论 -
PAT 1014 福尔摩斯的约会
#include <iostream>#include <cstring>#include <sstream>using namespace std;void DAY(string res[]){ if(res[0]=="A") { res[0] = "MON"; } if(res[0]=="B") { res[0] = "TUE"; } if(res[0]=="C") { res[0] = "WED"; } if(r.原创 2022-01-20 13:39:03 · 550 阅读 · 0 评论 -
PAT 1013 数素数
#include <iostream>#include <cmath>using namespace std;int s[10000];int j = 0;int judge(int n){ for(int i=2;i<=sqrt(n);i++) { if(n%i==0) { return 0; } } s[j] = n; j++; return 1; }.原创 2022-01-19 22:06:14 · 281 阅读 · 0 评论 -
PAT 1012 数字分类
1.需要认真看题2.注意A2#include <iostream>#include <iomanip>#include <stdlib.h>using namespace std; int main(){ int k=0; int n; cin>>n; int *s = (int*)malloc(sizeof(int)*n); while(k<n) { ..原创 2022-01-19 12:49:31 · 296 阅读 · 0 评论 -
PAT 1011 A+B和C
#include <iostream>#include <cmath>using namespace std; int main(){ int n; cin>>n; double a,b,c; string t[100000]; int count=0; for(int i=0;i<n;i++) { cin>>a>>b>>.原创 2022-01-18 20:18:32 · 161 阅读 · 0 评论 -
PAT 1010 一元多项式求导
1.需要注意,若一开始(即数组下标为0 , 1) 输入了指数为 0 ,即s[1] = 0 , 则说明输入了所谓零多项式直接输出 0 0,且结束程序。如直接输入 1 0 ,即 s[0] = 1, s[1] =0,因为指数为 0 且下标为 1 则直接输出 0 0 。其中s[0]即系数的值无所谓是多少。关键在于指数 s[1] 的值。2.若是在末尾(题也说了指数是递减输入,所以若要后面出现指数0,则必定是最后一个)输入了指数为 0 则忽略不计。 如 3 2 1 0,则可以看到指数为 0 ,但因为其...原创 2022-01-18 11:18:39 · 226 阅读 · 0 评论 -
PAT 1009 说反话
#include <iostream>#include <cstring>#include <stdlib.h>using namespace std; int main(){ string s[10000]; int k=0; while(cin>>s[k++]) { if(cin.get()=='\n') break; } fo.原创 2022-01-17 20:11:23 · 141 阅读 · 0 评论 -
PAT 1008 数组元素循环右移问题
1.建立函数方法:保存最后一个,依次让前面的放入后面即可。第一个等于保存的最后一个。2.右移几位,则操作几回函数方法。#include <iostream>#include <cstring>#include <cmath>#include <stdlib.h>using namespace std; void move_arr(int A[],int n){ int temp = A[n-1]; for(.原创 2022-01-16 19:33:31 · 170 阅读 · 0 评论 -
PAT 1007 素数对猜想
1不是素数,2是素数。 若判断n是否为素数,则就让 n 只存在 n%1 = 0, n%n = 0;则说明n为素数。#include <iostream>#include <cstring>#include <stdlib.h>#include <cmath>using namespace std; int s[100000];int j=0;//这个方法时间复杂度大些,时间会过int judge(int n){ ...原创 2022-01-15 21:50:43 · 207 阅读 · 0 评论 -
PAT 1006 换个格式输出整数
#include <iostream>#include <cstring>#include <stdlib.h>using namespace std; int main(){ int n; cin>>n; int h = n/100; int s = n%100/10; int g = n%10; string x; if(h!=0) { ..原创 2022-01-14 20:42:54 · 89 阅读 · 0 评论 -
PAT 1005 继续(3n+1)猜想
1.需要注意数组稍微大些。2.有些数据不用进行检查,如题中给出的数据 A: 3 5 6 7 8 11。其中3作为第一个数,那是必然需要进行检查的,3 会循环出 儿子数: 5 8 4 2 1,其中将 5 8 4 2 1 记录下来即可,而 母亲数 3 就不用保存了,之后进行到 A中的5,因为儿子数中已经记录下来了5故而这个就不必再执行了,直接到下一个A中的数 6 ,6很明显儿子数中没有,所以对其进行操作,会得到 6 的儿子数:3 5 8 4 2 1,果断记录下来,可以发现6的儿子数中出现了 3,所以就知道,原创 2022-01-13 22:46:19 · 704 阅读 · 0 评论 -
PAT 1004 成绩排名
1.注意一下,数组大小即可。使用了冒泡排序和快速排序,冒泡稍微简洁点,不过平均时间复杂度来说,快速排序要小些。#include <iostream>#include <cstring>#include <stdlib.h>using namespace std;struct stu{ string name; string number; int score;};// quick sort 快速排序void Qsort(stu* s原创 2022-01-12 21:01:06 · 220 阅读 · 0 评论 -
PAT 1003 我要通过
1.需要注意一下 A的个数,满足P左边A的个数设为 x1 ,P T之间A的个数设为x2,T右边的A个数设为x3,其 满足 x1 * x2 = x3,且P T之间必须要存在至少一个 A。#include <iostream>#include <cstring>//P T 只能有一个,且其余只能为 A,除此之外,顺序为 P A T //找出错误的即可A PAT A using namespace std;string judge(string x){原创 2022-01-11 21:25:51 · 232 阅读 · 0 评论 -
PAT 1002 写出这个数
用了最直接的操作:需要注意百位为0,则不输出,如 012 直接输出 yi er 即可,且002直接输出 er 即可,若为 000 则输出ling即可。#include <iostream>#include <cstring>using namespace std; string zifu(int n){ if(n==0) { return "ling"; } else if(n==1) { return "yi"; }原创 2022-01-10 18:52:26 · 304 阅读 · 0 评论 -
Basic Usage of Queue
We can know some things from the book.#include <iostream>#include <stdlib.h>using namespace std;typedef int QueueElementType;// Generally, the operation is to package the head pointer of the queue and the tail pointer of the queue...原创 2020-09-14 20:41:25 · 68 阅读 · 0 评论 -
动态规划之背包问题实现——简单明了——输入数据及不输入数据的情况
动态规划其实就是将大的问题分解为小问题,通过小问题的解最终得到大问题的解。 若实在不理解的,可以去看看算法图解这本书,对于这个背包问题有着详细的讲诉。(这书随便一搜就能搜到的)。 首先给出背包问题:算法图解书中的例子:一个小贼正在一家店里偷商品,商品如下图: 问,小偷的背包容量为 4 ,如何偷?偷那几样东西,能够保证在满足背包容量的情况下,偷的价值最高。(可能一辈子就这一次机会了,不能白干!) 首先容量为 4 那么我们可以将容量变为为 1 、2、3...原创 2020-08-26 15:54:27 · 213 阅读 · 0 评论 -
堆排序—直观明了——c++版
1.首先我们应该知道堆排序是如何实现的,其实无非就由3个函数方法模块组成:重建堆方法,建初堆方法,及一个综合调用前两个方法的heapsort方法。2.若以上的重建堆,和建初堆,不算太了解的话,可以去随便找一本数据结构的书籍进行阅读即可,这里推荐《数据结构——用C语言描述》中关于堆排序的介绍,强烈推荐去观看书籍所讲述的内容,非常的仔细与直观,或许很多时候一味的去查阅别人的所得虽然很快就能知道一些大概,不过若能认真的观看书籍中的内容,想来收获定然有着大大的不同。3.首先给出重建堆的代码://重建堆原创 2020-09-08 22:01:38 · 108 阅读 · 0 评论 -
Basic Usage of Circular Queue
Look at my code.#include <iostream>using namespace std;#define MAXSIZE 50typedef int QueueElementType; // type of variable// Circular Queue// The Circular Queue's difinition of the structuretypedef struct{ QueueElementType element...原创 2020-09-15 21:12:30 · 109 阅读 · 0 评论 -
C++对二维数组某一行或某一列或多行、多列进行升序及降序_sort函数直接法_冒泡排序法
1.首先若使用sort()函数直接来进行排序的话,则使用的二维数组应利用 vector< vector<int> > totalnum;这样的来定义二维数组 首先将数据压入到一个一维数组 vector<int> nums;中之后将nums压入到totalnum中即可完成二维数组数据的添加 首先定义好大小,如 规定大小为 4 行 3列 //之前规定了大小为 4 行 3 列 vector<vector<int> total...原创 2020-08-22 19:01:43 · 3855 阅读 · 0 评论 -
Basic Usage of Sequential Stacks and it‘s C++ program
First, we can know somebasic methods such as pop、push from the book原创 2020-09-14 20:31:27 · 69 阅读 · 0 评论 -
Operations on single-chain lists
1.First, we should know how to create a single-chain list. We can read a book to acquire answers. Here, I recommend a book. Its name is Data structure as described in C language. Now, I will introduce two methods to create a single-chain list: ...原创 2020-09-12 15:59:34 · 144 阅读 · 0 评论