
数据结构与算法
.
侯一鸣Supermonkey
more code,less dream.
展开
-
BJFUOJ
上机题:2018.04#include<bits/stdc++.h>using namespace std;void FindSub(int a[], int b[], int i, int n) { if (i >= n) { cout << "[ "; for (int j = 0; j < n; j++) { if (b[j] == 1) { cout << a[j] << " "; } } cou原创 2022-03-21 21:28:03 · 644 阅读 · 0 评论 -
BJFUOJ
上机题:2018.03#include<bits/stdc++.h>using namespace std;int maxx = -0x7fffffff;typedef struct BiTnode{ int data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &b,int a[],int &i){ if(a[i] == 0) b = NULL; else{ b原创 2022-03-21 20:15:39 · 549 阅读 · 0 评论 -
BJFUOJ
上机题:2018.01#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int data; struct Lnode *next;} Lnode, *Linklist;void Init_Linklist(Linklist &l) { l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l, int原创 2022-03-20 20:41:49 · 458 阅读 · 0 评论 -
BJFUOJ
上机题:2019.04#include<bits/stdc++.h>using namespace std;typedef struct BiTnode{ char data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '#'){ t = NULL; }else{ t = new BiTnode;原创 2022-03-17 20:56:50 · 310 阅读 · 0 评论 -
BJFUOJ
上机题:2019.02#include<bits/stdc++.h>using namespace std;int main(){ int a = 1,b = 1,c = 1; char s[100]; cin>>s; int i = 0; while(s[i] == s[i+1]){ a++; i++; } i++; while(s[i] == s[i+1]){ b++; i++; } i++; while(s[i] == s[i+1])原创 2022-03-14 21:06:28 · 676 阅读 · 0 评论 -
BJFUOJ
上机题:2019.01#include<bits/stdc++.h> using namespace std; int main(){ int a[15]; int maxx = -0x7fffffff; for(int i=0;i<10;i++){ cin>>a[i]; if(a[i] > maxx){ maxx = a[i]; } } for(int i=0;i<=4;i++){原创 2022-03-14 20:20:23 · 431 阅读 · 0 评论 -
BJFUOJ
2021.03#include<bits/stdc++.h>using namespace std;bool flag = true;typedef struct BiTnode { char data; struct BiTnode *lchild, *rchild;} BiTnode, *BiTree;void CreatTree(BiTree &l, char c) { if (l == NULL) { l = new BiTnode; l->d原创 2022-03-14 19:35:29 · 1641 阅读 · 0 评论 -
BJFUOJ
2021.02#include<bits/stdc++.h>using namespace std;int main(){ while(1){ char s[100]; int lenDev = 0; int lenExt = 0; cin>>s; int lens = strlen(s); for(int i=0;i<lens;i++){ if(s[i] == ':' && lenDev == 0){ lenDe原创 2022-03-13 20:48:18 · 657 阅读 · 0 评论 -
BJFUOJ
2021.01#include<bits/stdc++.h>using namespace std;int maxx = -0x7fffffff;typedef struct Lnode{ int data; struct Lnode *next;}Lnode,*Linklist;void Init_Linklist (Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Link原创 2022-03-13 19:33:34 · 589 阅读 · 0 评论 -
BJFUOJ:基于二叉链表的二叉树最大宽度的计算
BJFUOJ:基于二叉链表的二叉树最大宽度的计算#include<bits/stdc++.h>using namespace std;int maxWide = -1;typedef struct BiTnode{ char data; int deepth; struct BiTnode *lchile,*rchild;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i,int d){ if(原创 2022-03-12 09:45:50 · 2128 阅读 · 0 评论 -
BJFUOJ:删除链表中绝对值相等的结点
BJFUOJ:删除链表中绝对值相等的结点#include<bits/stdc++.h>using namespace std;set <int> s;typedef struct Lnode { int data; struct Lnode *next;} Lnode, *Linklist;void Init_Linklist(Linklist &l) { l = new Lnode; l->next = NULL;}void Creat_L原创 2022-03-11 20:25:56 · 2798 阅读 · 2 评论 -
BJFUOJ:基于链表的两数之和
BJFUOJ:基于链表的两数之和#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int data; struct Lnode *next;}Lnode,*Linklist;void Init_Linklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinlist(Linklist &l,int n原创 2022-03-11 19:45:27 · 1445 阅读 · 0 评论 -
BJFUOJ:奇偶链表的分割
BJFUOJ:奇偶链表的分割#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int data; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l,int n)原创 2022-03-11 18:40:28 · 1555 阅读 · 1 评论 -
BJFUOJ:基于栈的回文字符序列判断
BJFUOJ:基于栈的回文字符序列判断#include<bits/stdc++.h>using namespace std;stack <int> st;int main() { while (1) { int flag = 1; char s[100]; cin >> s; if (s[0] == '0') break; int len = strlen(s); if (len % 2 == 0) { int i; for原创 2022-03-11 10:26:51 · 1101 阅读 · 0 评论 -
BJFUOJ:链表的分解
BJFUOJ:链表的分解#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int data; struct Lnode *next;} Lnode, *Linklist;void Init_Linklist(Linklist &l) { l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l, in原创 2022-03-10 20:59:59 · 1056 阅读 · 0 评论 -
BJFUOJ:基于链表的简单选择排序
BJFUOJ:基于链表的简单选择排序#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int data; struct Lnode *next;} Lnode, *Linklist;void Init_Linklist(Linklist &l) { l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &原创 2022-03-10 17:21:47 · 1111 阅读 · 0 评论 -
BJFUOJ:查找链表中倒数第k个结点
BJFUOJ:查找链表中倒数第k个结点#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int num; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l,int原创 2022-03-10 16:47:30 · 155 阅读 · 0 评论 -
BJFUOJ:交换链表中相邻的两个结点
BJFUOJ:交换链表中相邻的两个结点#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int data; struct Lnode *next;} Lnode, *Linklist;void Init_Linklist(Linklist &l) { l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &原创 2022-03-10 16:46:06 · 320 阅读 · 0 评论 -
BJFUOJ:二叉排序树的判定
BJFUOJ:二叉排序树的判定#include<bits/stdc++.h>using namespace std;typedef struct BiTnode{ char data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '#') t = NULL; else{ t = new BiTnode;原创 2022-03-09 21:17:44 · 725 阅读 · 0 评论 -
BJFUOJ:基于二叉链表的二叉树左右节点的交换
BJFUOJ:基于二叉链表的二叉树左右孩子的交换#include<bits/stdc++.h>using namespace std;typedef struct BiTnode{ char data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '0'){ t = NULL; }else{ t =原创 2022-03-09 20:57:25 · 687 阅读 · 0 评论 -
BJFUOJ:基于二叉链表的二叉树高度的计算
BJFUOJ:基于二叉链表的二叉树高度的计算#include<bits/stdc++.h>using namespace std;int high;typedef struct BiTnode{ char data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '0'){ t = NULL; }else原创 2022-03-09 20:37:05 · 661 阅读 · 0 评论 -
BJFUOJ:基于二叉链表的二叉树结点个数的统计
BJFUOJ:基于二叉链表的二叉树结点个数的统计易错点:便利二叉树的时候不要忘记 if(t) 这个条件#include<bits/stdc++.h>using namespace std;int node2,node1,node0;typedef struct BiTnode{ char data; struct BiTnode *left,*right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &a原创 2022-03-09 20:35:08 · 935 阅读 · 0 评论 -
BJFUOJ:基于二叉链表的二叉树的遍历
BJFUOJ:基于二叉链表的二叉树的遍历#include<bits/stdc++.h>using namespace std;typedef struct BiTnode{ char data; struct BiTnode *left; struct BiTnode *right;}BiTnode,*BiTree;void CreatTree(BiTree &t,char s[],int &i){ if(s[i] == '0') t = NULL; els原创 2022-03-08 20:24:21 · 794 阅读 · 0 评论 -
BJFUOJ:查找子串第一次出现的位置
BJFUOJ:查找子串第一次出现的位置strle() 返回数组的长度,X.length() X需要为字符串cin输入的字符串不能包含空格,gets可以包含空格#include<bits/stdc++.h>using namespace std;int Find (char s1[],char s2[]){ int len1 = strlen(s1); int len2 = strlen(s2); for(int i=0;i<len1;i++){ int j1 = i;原创 2022-03-08 17:50:37 · 1724 阅读 · 1 评论 -
BJFUOJ:二维数组中的元素查重
BJFUOJ:二维数组中的元素查重坑点:利用SET查找重复元素,注意每次把SET给清空#include<bits/stdc++.h>using namespace std;set<int> s;int a[1000][10000];int main() { while(1) { s.clear(); int n,m,flag = 0; cin>>n>>m; if(n==0 && m==0) break; mem原创 2022-03-06 19:59:16 · 818 阅读 · 0 评论 -
BJFUOJ:字符串的插入
BJFUOJ:字符串的插入坑点:少了这一句就wa,“ s[lent+lens] = ‘\0’; ” ,不太理解为什么???#include<bits/stdc++.h>using namespace std;char s[100000];char t[100000];void insert(char s[],char t[],int pos) { int lent = 0,lens = 0; while(t[lent] != '\0') { lent++; } while原创 2022-03-06 18:01:29 · 333 阅读 · 0 评论 -
BJFUOJ:查找链表中倒数第k个结点
BJFUOJ:查找链表中倒数第k个结点#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int num; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l,int原创 2022-03-05 21:23:11 · 508 阅读 · 0 评论 -
BJFUOJ:删除链表中满足区间值的结点
BJFUOJ:删除链表中满足区间值的结点#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int num; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l,in原创 2022-03-05 21:16:49 · 392 阅读 · 0 评论 -
BJFUOJ:查找链表中的最大值
BJFUOJ:查找链表中的最大值#include<bits/stdc++.h>using namespace std;int maxx = -0x7fffffff;typedef struct Lnode { int num; struct Lnode *next;} Lnode,*Linklist;void InitLinklist(Linklist &l) { l = new Lnode; l->next = NULL;}void CreatLink原创 2022-03-05 20:06:38 · 730 阅读 · 0 评论 -
BJFUOJ:基于链表的两个集合的差集
BJFUOJ:基于链表的两个集合的差集#include<bits/stdc++.h>using namespace std;int num = 0;typedef struct Lnode{ int num; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linkli原创 2022-03-05 19:50:47 · 937 阅读 · 0 评论 -
BJFUOJ:基于链表的两个集合的交集
BJFUOJ:基于链表的两个集合的交集#include<bits/stdc++.h>using namespace std;typedef struct Lnode{ int num; struct Lnode *next;}Lnode,*Linklist;void InitLinklist(Linklist &l){ l = new Lnode; l->next = NULL;}void CreatLinklist(Linklist &l,int原创 2022-03-05 19:49:25 · 316 阅读 · 0 评论 -
BJFUOJ:基于链表的两个非递减有序序列的合并
BJFUOJ:基于链表的两个非递减有序序列的合并单链表的排序可以在创建链表的时候进行排序,也可以创建好后采用类似冒泡排序的方法就行(比数组的冒泡排序略微浪费时间)#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int num; struct Lnode *next;} Lnode,*Linklist;void InitLinklist(Linklist &l) { l = new Ln原创 2022-03-04 21:30:02 · 1178 阅读 · 0 评论 -
BJFUOJ:基于链表的两个递增有序序列的合并
基于链表的两个递增有序序列的合并坑点:(1) 注意空间复杂度为o(1)(2) 输出的每一行最后一个数字后面不要有空格,否则会wa#include<bits/stdc++.h>using namespace std;typedef struct Lnode { int num; struct Lnode *next;} Lnode,*Linklist;void InitLinklist(Linklist &l) { l = new Lnode; l->next原创 2022-03-04 20:56:31 · 809 阅读 · 0 评论 -
数据结构:各种排序算法的比较
数据结构:各种排序算法的比较#include<bits/stdc++.h>using namespace std;int l[10000000];long long length,com=0,move=0,t;//数据存储,长度,比较次数,移动次数。void insertsort(int *l) //直接插入排序。{ com=move=0; for(int i=2;i<=length;i++) { com++; if(l[i]<l[i-1]) {原创 2022-01-16 13:49:49 · 656 阅读 · 0 评论 -
BJFUOJ:基于链存储结构的图书信息表的图书去重
BJFUOJ:基于链存储结构的图书信息表的图书去重代码#include<bits/stdc++.h>using namespace std;int n;int num;set <string> s;struct book{ string bookno; string name; double price;};typedef struct Lnode{ book data; struct Lnode *next;}Lnode,*Linklist;vo原创 2022-01-09 21:24:58 · 1693 阅读 · 1 评论 -
BJFUOJ:基于链式存储结构的图书信息表的排序
BJFUOJ:基于链式存储结构的图书信息表的排序代码#include<bits/stdc++.h>using namespace std;using namespace std;int length = 0; struct book{ string bookno; string name; double pride;};typedef struct Lnode{ book data; struct Lnode *next;}Lnode,*Linklist;voi原创 2022-01-09 19:27:38 · 1112 阅读 · 0 评论 -
BJFUOJ:基于链式存储结构的图书信息表的创建和输出
BJFUOJ:基于链式存储结构的图书信息表的创建和输出代码#include <bits/stdc++.h>using namespace std;int i = 0;struct book{ string bookno; string name; double price;};typedef struct Lnode{ book data; struct Lnode *next;}Lnode,*Linklist;void Init_list(Linklist &a原创 2022-01-09 17:18:10 · 2373 阅读 · 2 评论 -
GCD + LCM + 素数打表 + 快速幂
1gcd为两个数的最大公因数gcd模板int gcd (a , b ) {return b ? gcd (b , a % b ) : a ;} 2lcm为两个数的最小公倍数lcm(a,b)=(a*b)/gcd(a,b)3素数打表//求0~100000以内的素数//(下标为0的是素数,下标不为0的为合数)bool str[100010];void prime(){ ...原创 2019-08-22 10:30:25 · 172 阅读 · 0 评论 -
sort排序
sort 排序函数是在 C++ 中的一个库函数,它所在的头文件为 algrithm.h,它其实就是对快速排序算法的封装,只需要一行代码即可实现快速排序它的时间复杂度为 O(n ∗ log(n))形式:sort(参数一, 参数二,参数三)使用范围: 数组结构体 sting 队列 vector……1对数组 a 从小到大排序int a[5]={2,1,3,4,5};sort(a,a+5...原创 2019-08-22 10:11:47 · 223 阅读 · 0 评论 -
洛谷p1028 数的计算
//记忆化搜索题目描述我们要求找出具有下列性质数的个数(包含输入的自然数n):先输入一个自然数n(n≤1000),然后对此自然数按照如下方法进行处理1 不作任何处理;2 在它的左边加上一个自然数,但该自然数不能超过原数的一半;3 加上数后,继续按此规则进行处理,直到不能再加自然数为止.输入6输出6说明/提示满足条件的数为6,16,26,126,36,136AC code...原创 2020-02-04 16:22:44 · 378 阅读 · 0 评论