![](https://img-blog.csdnimg.cn/20190927151124774.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
数据结构
数据结构+各平台OJ
马甲都掉光了
这个作者很懒,什么都没留下…
展开
-
【PAT】7-3 Postfix Expression (25) +1130 Infix Expression (25)
俺也不知道对不对,两个给的样例是过了的没有左结点但有右结点的结点要先输出,这是为什么?#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<algorithm>#include<string>using namespace std;struct Node{ string key; int lchild,rchild; bool flag;//设定flag是因为题结点没有左节点,但...原创 2020-07-17 21:59:42 · 335 阅读 · 0 评论 -
【PAT】1147 Heaps (30分) [heap]
1147 Heaps (30分)#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <vector>#include<string>using namespace std;//m个堆,每个堆n个结点//输出最大/最小/不是堆 + 后序遍历vector<int>v;int m, n;void postOrder(int index){ if (index > n)原创 2020-07-17 12:15:36 · 122 阅读 · 0 评论 -
【PAT】1155 Heap Paths (30) [heap]
1155 Heap Paths (30分)#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <vector>#include<string>using namespace std;//完全二叉树层序求路径(右到左)dfs//判断是否为大根/小根堆vector<int>v;int h[1001], n, Min = 1, Max = 1;void dfs(int inde原创 2020-07-17 00:14:49 · 121 阅读 · 0 评论 -
【PAT】7-1 Good in C (20) [print]
给出26个字母图形和一个字符串,输出字符串的图形没在pat上提交过,不知道能不能ac用vector[26][7]存字母,vector[i][j]代表字母j的第j行#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <vector>#include<string>using namespace std;int main() { vector<string> v[26];原创 2020-07-16 18:01:56 · 123 阅读 · 0 评论 -
【PAT】1052 Linked List Sorting (25) [list]
1052 Linked List Sorting (25分)链表的地址一定记得printf("%05d\n")否则会有部分测试点过不了#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<algorithm>#include<vector>using namespace std;struct Node{ int address; int key; int next; bool flag原创 2020-07-15 19:08:31 · 100 阅读 · 0 评论 -
【PAT】1032 Sharing (25) [list]
1032 Sharing (25分)#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<map>#include<string>#include<vector>using namespace std;struct node { char key; int next; bool flag;}node[100000];int main(){ //freopen("inp原创 2020-07-15 18:00:42 · 102 阅读 · 0 评论 -
【PAT】1138 Postorder Traversal (25) [tree][traversal]
1138 Postorder Traversal (25分)Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence先序中序转后序,输出后序第一个结点#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector原创 2020-07-14 16:16:51 · 87 阅读 · 0 评论 -
【PAT】1020 Tree Traversals (25) [tree][traversal]
1020 Tree Traversals (25分)后序+中序转层序node保存结点标号,按标号升序输出//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>#include<algorithm>using namespace std;struct node{ int id;//按完全二叉树的下标 int val;//值};bool cmp(node a, nod原创 2020-07-14 15:52:55 · 121 阅读 · 0 评论 -
【PAT】1004 Counting Leaves (30) [tree][dfs]
1004 Counting Leaves (30分)使用dfs,每搜索到一个叶子结点leaf[层数]++,最后输出leaf数组即可#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<vector>using namespace std;//求每层叶子结点int n, m;// 0 < N < 100, the number of nodes in a tree// M(< N),原创 2020-07-10 15:53:20 · 97 阅读 · 0 评论 -
【PAT】1034 Head of a Gang (30) [graph][dfs]
1034 Head of a Gang (30分)牛客 1034 Head of a Gang (30分)测试点3排序后正确其他测试点…快被整疯了,牛客上可以过PAT过不了测试点1和2应该是输出0,其他的应该是输出格式问题?#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>#include<vector>#include<map>using namespa原创 2020-07-09 15:12:17 · 139 阅读 · 0 评论 -
【PAT】1021 Deepest Root (25) [graph][dfs]
dfs统计连通分量数dfs找到最深点记作A,再次以A为起点dfs,得到Deepest Root原创 2020-07-07 15:42:06 · 88 阅读 · 0 评论 -
【PAT】1013 Battle Over Cities (25) [graph][dfs]
1013 Battle Over Cities (25分)连通图去除某个顶点,需要加几条路径使其再次连通思路连通图去除某个顶点 --> 变成k个连通分量 --> k个连通分量需要增加k-1条路线使其再次连通即:求出去掉顶点后,求出图的连通分量数即可知识点dfs查找连通分量数k个连通分量需要增加k-1条路线使其再次连通fill(visited, visited + 1000, false);cin / cout 会超时,换成scanf / printf//参考柳神//原创 2020-07-02 17:42:26 · 89 阅读 · 0 评论 -
【PAT】1015 Reversible Primes (20) [prime][Binary conversion]
1015 Reversible Primes (20分)进制参考bool isPrime(int n)while(cin >> n && n>=0)输入小于零结束for (int i = 0; i < len; i++) n = n * d + arr[i];///化十进制①进制转换自己实现int len = 0, arr[100];//进制转换 do { arr[len++] = n % d; n = n / d; } while原创 2020-06-30 17:12:00 · 153 阅读 · 0 评论 -
【PAT】1005 Spell It Right (20) [string]
1005 Spell It Right (20分)忘记这种写法了,string arr[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>using namespace std;int main(){ //fre原创 2020-06-30 16:19:58 · 105 阅读 · 0 评论 -
【PAT】1152 Google Recruitment (20) [string][prime]
1152 Google Recruitment (20分)isPrime输出字符串,不要输出转换后的int//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>using namespace std;bool isPrime(int n){ if (n == 0 || n == 1) return false; for (int i = 2; i*i <= n; i++)原创 2020-06-29 16:54:58 · 168 阅读 · 0 评论 -
【PAT】1108 Finding Average (20) [string]
1108 Finding Average (20分)strlen在cstring里sscanf从字符串读进与指定格式相符的数据sprintf格式化数据//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<cstring>using namespace std;int main(){ //freopen("input.txt","r", stdin); int N,cnt = 0; doub原创 2020-06-28 19:17:54 · 107 阅读 · 0 评论 -
【PAT】1077 Kuchiguse (20)[string]
1077 Kuchiguse (20分)只能通过第一个测试点,在牛客上看了其他测试点,在我的机器上可以跑出来,但是牛客上的答案就不对....这到底是为什么!!!reverse头文件 algorithmfind//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>#include<algorithm>using namespace std;int main()原创 2020-06-28 17:11:47 · 119 阅读 · 0 评论 -
【PAT】1073 Scientific Notation (20) [string]
1073 Scientific Notation (20分)PAT上有个例子没跑通,没找出来,只是部分正确18分//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include <cstdlib>#include<string>using namespace std;int main(){ //freopen("input.txt","r",stdin); string s; cin >原创 2020-06-25 21:37:41 · 119 阅读 · 0 评论 -
【PAT】1061 Dating (20) [string]
1061 Dating (20分)发现了个函数isalpha / isdigit ,刚开始一直写的是>'A'这种string week[7] = { "MON ", "TUE ", "WED ","THU ","FRI " ,"SAT ","SUN " }; week[time[0] - 65];printf("%02d", pos);对输出格式控制//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<原创 2020-06-25 15:02:38 · 121 阅读 · 0 评论 -
【PAT】1001 A+B Format (20) [string]
1001 A+B Format (20)(i + 1) % 3 == len % 3//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>using namespace std;int main(){ //freopen("input.txt", "r",stdin); int a, b,len; cin >> a >> b; string s = .原创 2020-06-24 19:27:08 · 127 阅读 · 0 评论 -
【PAT】1035 Password (20) [string]
1035 Password (20分)注意输出的is / are 和 account / accounts//#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>#include<vector>using namespace std;int main(){ //freopen("input.txt","r",stdin); vector<string>v; i原创 2020-06-24 19:24:44 · 144 阅读 · 0 评论 -
【PAT】1054 The Dominant Color (20) [map]
Behind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than原创 2020-05-20 23:23:06 · 100 阅读 · 0 评论 -
【PAT】1081 Rational Sum (20) [gcd]
题目描述:Given N rational numbers in the form “numerator/denominator”, you aresupposed to calculate their sum.输入描述:Each input file contains one test case. Each case starts with apositive integer N (<=100), followed in the next line N rationalnumber原创 2020-05-19 20:08:42 · 141 阅读 · 0 评论 -
【PAT】害死人不偿命的(3n+1)猜想
用迭代来解决的#include<iostream>//using namespace std; int Callatz(int a,int num){ if(a == 1) return num; if(a%2 != 0) a = (a*3+1); a /= 2; num += 1; Callatz(a,num);}int main(){ int...原创 2020-04-29 13:52:29 · 148 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树左右孩子的交换
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写递归算法交换该二叉树的左右孩子。输入多组数据。每组数据一行,为二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行。为交换左右孩子后的二叉树的先序序列。样例输入1abcd00e00f00ig00h00abd00e00cf00g00...原创 2018-11-26 23:34:33 · 4062 阅读 · 1 评论 -
【数据结构】基于二叉链表的二叉树最长路径的求解
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写算法求出该二叉树中第一条最长的路径。输入多组数据。每组数据一行,为二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行,第一行为二叉树的最长路径长度,第二行为此路径上从根到叶结点的各结点的值。样例输入1 复制abcd00e00f00ig00h00a...原创 2018-12-02 22:16:16 · 1730 阅读 · 0 评论 -
【数据结构】基于哈夫曼树的数据压缩算法
描述输入一串字符串,根据给定的字符串中字符出现的频率建立相应哈夫曼树,构造哈夫曼编码表,在此基础上可以对待压缩文件进行压缩(即编码),同时可以对压缩后的二进制编码文件进行解压(即译码)。输入多组数据,每组数据一行,为一个字符串(只考虑26个小写字母即可)。当输入字符串为“0”时,输入结束。输出每组数据输出2n+3行(n为输入串中字符类别的个数)。第一行为统计出来的字符出现频率(只输出存在...原创 2018-12-02 22:29:51 · 6120 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树的遍历
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写三个递归算法分别实现二叉树的先序、中序和后序遍历。输入多组数据。每组数据一行,为二叉树的前序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出三行,为二叉树的先序、中序和后序序列。样例输入1abcd00e00f00ig00h00abd00e00c...原创 2018-11-26 23:26:58 · 2164 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树结点个数的统计
基于二叉链表的二叉树结点个数的统计描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写三个递归算法分别对二叉树的结点(度为0、1、2)个数进行统计。输入多组数据。每组数据一行,为二叉树的前序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行,每行三个数分别为二叉树的度为0、1、2的结点个数。每两个数用空格分隔。...原创 2018-11-27 22:04:15 · 5404 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树的双序遍历
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写递归算法实现该二叉树的双序遍历(双序遍历是指对于二叉树的每一个结点来说,先访问这个结点,再按双序遍历它的左子树,然后再一次访问这个结点,接下来按双序遍历它的右子树)。输入多组数据。每组数据一行,为二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行,为双...原创 2018-11-27 22:22:54 · 3000 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树叶子结点到根结点的路径的求解
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写算法求出每个叶子结点到根结点的路径。输入多组数据。每组数据一行,为二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出n行(n为叶子结点的个数),每行为一个叶子结点到根节点的路径(按照叶子结点从左到右的顺序)。样例输入1 复制abcd00e00f00ig...原创 2018-11-30 18:52:11 · 2411 阅读 · 0 评论 -
【数据结构】基于二叉链表的二叉树最大宽度的计算
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写算法计算该二叉树的最大宽度(二叉树的最大宽度是指二叉树所有层中结点个数的最大值)。输入多组数据。每组数据一行,为二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行。为二叉树的最大宽度。样例输入1 复制abcd00e00f00ig00h00abd0...原创 2018-11-28 19:06:15 · 4557 阅读 · 8 评论 -
【数据结构】基于二叉链表的二叉树高度的计算
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,编写递归算法计算二叉树的高度。输入多组数据。每组数据一行,为二叉树的前序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据分别输出一行,为二叉树的高度。样例输入1 复制abcd00e00f00ig00h00abd00e00cf00g000样例输出143#inc...原创 2018-11-28 20:30:38 · 2330 阅读 · 0 评论 -
【数据结构】基于二叉链表的树结构相等的判断
描述设二叉树中每个结点的元素均为一个字符,按先序遍历的顺序建立二叉链表,按此方法创建两棵二叉树,然后编写递归算法判断这两棵树是否相等。输入多组数据,每组数据有两行。每行为一个二叉树的先序序列(序列中元素为‘0’时,表示该结点为空)。当输入只有一个“0”时,输入结束。输出每组数据输出一行。若两个二叉树相等输出“YES”,否则输出“NO”。样例输入1abcd00e00f0...原创 2018-11-26 23:31:01 · 3546 阅读 · 0 评论