- 博客(13)
- 收藏
- 关注
原创 数据结构复习笔记:图的概念和操作
数据结构复习笔记:图的概念和操作 一,图 1.图的定义: 图G(Graph)由俩个集合V(Vertex)和E(Edge)组成,记为G=(V, E),其中V是顶点的有限集合,E是连接V中顶点的边的有限集合。通常,也将图中的顶点集记为V(G),边集记为E(G)。 2.有向图和无向图: 如果E中的顶点对是有序的,即E中的每条边都是有方向的,则G称为有向图。如果顶点对是无序对,则称G为无向图。 3.弧和边: ①弧的定义:若G = (V,E)是有向图,则它的一条有向边是由V中俩个顶点构成的有序对,也叫做弧,记为<
2021-05-24 08:40:54
1863
原创 数据结构复习笔记:栈和队列
数据结构复习:栈和队列 栈 1.栈的定义:栈是一种操作受限的线性表,只允许在表的同一端进行插入和删除操作。 2.栈的特性:后进先出(Last in First out, LIFO)。 3.栈的实现: ①c语言版(简单实现),确保peek,pop,操作的合法性: #include <stdio.h> #define Maxn 10005 int Arr[Maxn], top = -1; void push(int x) { Arr[++top] = x; } int empty()
2021-05-21 17:29:50
250
原创 PAT 1011 A+B 和 C (15 point(s))
PAT 1011 A+B 和 C (15 point(s)) 解题思路: int 的范围是[-231,231),所以单纯的int并不能真正的容纳[-231,231]之间的所有数,同样的long也不行,只能用long long,鉴于数据较大,用scanf读入。 #include <iostream> #include <cstdio> using namespace std; int main() { int n, R[10]{}; cin >> n; fo
2021-02-27 07:05:04
166
原创 PAT 1010 一元多项式求导 (25 point(s))
PAT 1010 一元多项式求导 (25 point(s)) 解题思路: 对于一元函数求导大家并不陌生,只需注意空格的位置和特殊项0 0。 #include <iostream> #include <vector> using namespace std; int main() { vector<int> v; int tem; while (cin >> tem) v.push_back(tem); if (!v.size() || v[1]
2021-02-27 06:38:40
209
原创 PAT 1008 数组元素循环右移问题 (20 point(s))
PAT 1008 数组元素循环右移问题 (20 point(s)) 解题思路: 程序移动次数尽量少,最好的方法就是不移动????。 #include <iostream> using namespace std; int main() { int n, m, arr[100], move, begin; cin >> n >> m; for (int i = 0; i < n; i++) cin >> arr[i]; move = m %
2021-02-03 10:51:24
142
原创 PAT 1007 素数对猜想 (20 point(s))
PAT 1007 素数对猜想 (20 point(s)) 解题思路: 先判断是不是素数,再看它与前一个素数相差是不是2。 #include <iostream> using namespace std; bool IsPrime(int x); int main() { int n, past = 3, count = 0; cin >> n; for (int i = 3; i <= n; i += 2) { if (IsPrime(i)) {
2021-02-03 10:23:24
144
原创 PAT 1006 换个格式输出整数 (15 point(s))
PAT 1006 换个格式输出整数 (15 point(s)) 解题思路: 无。 #include <iostream> using namespace std; int main() { int n, num[3] = { 0 }, count = 0; cin >> n; while (n != 0) { num[count] = n % 10; n /= 10; count++; } for (int i = 0; i < num[2]; i+
2021-02-03 10:02:59
115
原创 PAT 1005 继续(3n+1)猜想 (25 point(s))
PAT 1005 继续(3n+1)猜想 (25 point(s)) 解题思路: 对每个数字得到的答案都进行一次遍历数组,想法还很简单。 #include <iostream> using namespace std; int sort(int num[], int n); int main() { int n, num[100], count; cin >> n; for (int i = 0; i < n; i++) cin >> num[i]; f
2021-02-03 09:51:58
176
原创 PAT 1004 成绩排名 (20 point(s))
PAT 1004 成绩排名 (20 point(s)) 解题思路: 这道题是学生信息管理,因为要保存不同的数据类型,所以我采用了结构体数组来保存单个学生信息。 #include <iostream> using namespace std; struct Achievement { char name[11], num[11]; int ach = 0; }achievement[100]; void sort(int a); int main() { int n; cin
2021-02-02 20:12:20
170
原创 PAT 1003 我要通过! (20point(s))
PAT 1003 我要通过! (20point(s)) 解题思路: 这道题主要是进行字符串的检查,因为情况较为复杂,所以我进行了分类,分为开头是A和不是A以及其他字符三种情况,由题易知P和T中间一定有A且当满足第三种情况时,中间A的个数乘以前面A的个数等于后面A的个数,这是我们读题需要知道的。 #include <iostream> #include <string> using namespace std; int main() { int n, ans[10];
2021-02-02 19:09:48
198
原创 PAT 1002 写出这个数 (20point(s))
PAT 1002 写出这个数 (20point(s)) 解题思路: 对于这么大的数字当然不可能用%d去读入,应该是把他看成是一个字符串来处理,我们当然也不可能使用%s读入,太占空间,这个时候我们就可以一个字符一个字符处理,处理完就丢掉。 #include <iostream> using namespace std; int main() { char pinyin[10][10] { "ling" , "yi", "er", "san", "si", "wu", "liu", "qi"
2021-02-02 06:34:48
169
原创 1001 害死人不偿命的(3n+1)猜想 (15point(s))
PTA 1001 害死人不偿命的(3n+1)猜想 (15point(s)) 这道题主要是注意审题,对于奇数需要(3n+1)/2算作一步;可以省略一些无关判断,比如if,else条件处。 #include <iostream> using namespace std; int main() { int n, count = 0; cin >> n; while (n != 1) { if (n % 2) { n = (3 * n + 1) / 2; c
2021-01-17 23:09:31
148
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅