自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

晴空

仰望星空,脚踏实地

  • 博客(134)
  • 收藏
  • 关注

原创 (算法练习)——问题 1012: [编程入门]字符串分类统计

水题,but为什么不是正确!!样例都是对的= =(答案错误50%)#include <stdio.h>#include <algorithm>#include <string>#include <iostream>using namespace std;int main(){ string str[500];//i就是空格数 i...

2020-01-31 21:06:24 300

原创 (算法练习)——二叉树的各种遍历

先序、中序、后序都是用递归实现的,没啥好说的代码://先序遍历void preorder(node* root){ if(root == NULL){ return; } printf("%d\n",root->data);//访问根节点root,如输出数据等 //访问左子树 preorder(root->lchild); //访问右子树 preorder(r...

2020-01-31 15:55:44 97

原创 (算法练习)——二叉树存储结构与基本操作

存储结构与基本的操作//二叉树的创建struct node{ int data; node* lchild;//指向左子树根节点的指针 node* rchild;//指向右子树根节点的指针 }; //二叉树建树前根节点不存在,其地址一般设为NULL node* root = NULL;//生成一个新节点,v为节点权值 node* newNode(int v){ node* ...

2020-01-31 15:12:12 187

原创 关于queue的数据修改

简单说,修改队列中的元素不改变原元素;修改原元素也不改变队列中的元素代码:#include <stdio.h>#include <queue>using namespace std;struct node{ int data;}a[10];int main(){ queue<node> q; for(int i = 1;i <= 3...

2020-01-31 12:14:56 3012

原创 (算法练习)——问题 1004: [递归]母牛的故事

要求:https://www.dotcpp.com/oj/problem1004.html说明:用函数,时间超限了关于递归掌握的并不好,贴两段代码:超限代码:#include <stdio.h>int sum;int F(int n){ if(n == 1){ sum = 1; } else if(n == 2){ sum = 2; } else i...

2020-01-31 09:55:18 244

原创 (算法练习)——BFS(广度优先搜索)【出迷宫】

《算法笔记》P280这一题值得珍藏!!#include <stdio.h>#include <string.h>#include <queue>using namespace std;const int maxn = 100;struct node{ int x,y;//位置{x,y} int step;//step为从起点S到大该位置的最少...

2020-01-30 18:57:56 202

原创 (算法练习)——BFS(广度优先搜索)

《算法笔记》P276感觉这一题最有意思的是判断元素的上下左右四个位置代码:#include <stdio.h>#include <queue>using namespace std;const int maxn = 100;struct node{ int x,y;}Node;int n,m;//矩阵的大小为n*m int matrix[maxn]...

2020-01-30 18:11:59 309

原创 (算法练习)——DFS(深度优先搜索)

用递归来实现深度优先搜索《算法笔记》P271背包问题#include <stdio.h>const int maxn = 30;int n,V,maxValue = 0;int w[maxn],c[maxn];/*void DFS(int index,int sumW,int sumC){ if(index == n){//死胡同 if(sumW <= V...

2020-01-30 13:55:57 191

原创 (算法练习)——PAT A1052 Linked List Sorting

《算法笔记》P265存疑:1、排序规则那里,无效节点放到后面去,什么意思?#include <stdio.h>#include <algorithm>using namespace std;const int maxn = 100005;struct NODE{ int address,data,next; bool flag;}node[maxn];...

2020-01-30 11:51:55 102

原创 (算法练习)——问题 1115: DNA

要求:https://www.dotcpp.com/oj/problem1115.html这一题搞了半天搞出来了,but,提交后发现自己审错题了!!!连续的符号是共用一条最长的边的!!记录下这个简单重复的代码:(想的太复杂,想的是逐行打印,且每行按照空格+符号+空格+符号看了题解发现要理清思路用规律,这句话对很多题适用!!)#include <stdio.h>int rec...

2020-01-30 10:23:37 207

原创 (算法练习)——CCF模拟【报数】

趁热打铁记录一下主要就是判断与7相关~#include <stdio.h>int main(){ int num; int a=0,b=0,c=0,d=0; scanf("%d",&num); for(int i=1;i<=num;i++){ if(i%7==0||i/100==7||i%10==7||i/10%10==7){ if(...

2020-01-29 17:22:07 379

原创 (算法练习)——PAT A1032 Sharing

这一题要说一下,输入格式里面直到-1才是一条链表的结束思路是使用静态链表保存两个链表的数据,并且查询有无共用节点《算法笔记》P263#include <cstdio>#include <string.h>const int maxn = 100010;struct NODE{ char data;//数据域 int next;//指针域 bool fl...

2020-01-29 15:40:58 164

原创 链表处理

0、为链表节点(动态)分配内存空间、释放C++下面的new使用方便,比较推荐//malloc的申请方式 typename* p = (typename*)malloc(sizeof(typename));int *p = (int*)malloc(sizeof(int));node *p = (node*)malloc(sizeof(node));//new的申请方式(c++中的)t...

2020-01-29 12:39:55 168

原创 队列的常见操作

示例代码,感觉这一部分应该结合数据结构的代码来多看看,可惜一时半会回不去。。队列先进先出//清空clear() void clear(){ front = rear = -1;}//获取队列内元素的个数size() int size(){ return rear - front;}//判空empty()bool empty(){ if(front == rear) retu...

2020-01-29 10:45:34 156

原创 STL中迭代器访问小结

对于string,map这两种典型的STL记录下,使用迭代器访问有点像结构体、指向结构体的指针的访问,其他vector也是*it访问string/vector/setcout<<*it<<endlmapcout<<(itt->first)<<" "<<(itt->second)<<endl;不过后续有...

2020-01-28 13:51:09 321

原创 (算法练习)——简单计算器

要求:http://codeup.cn/problem.php?cid=100000605&pid=0说明:栈、队列的使用;中缀表达式转后缀表达式《算法笔记》P250代码:#include <iostream>#include <stdio.h>#include <string>#include <stack>#inclu...

2020-01-28 13:16:13 550

原创 (算法练习)——C语言-数字交换

要求:http://codeup.cn/problem.php?cid=100000600&pid=0说明:这么简单的题都做不了满分真是让人惆怅。。。(代码提示答案错误= =)#include <stdio.h>#include <algorithm>using namespace std;int numrecord[20];int nummax[...

2020-01-27 21:37:31 304

原创 C++模板库STL——algorithm下的常用函数

跟着书做一个整理:0、max(),min(),abs()abs()中必须是整数;如果求浮点数的绝对值,使用fabs()#include <stdio.h>#include <algorithm>#include <math.h>using namespace std;int main(){ int x = 1,y = -2; printf("...

2020-01-27 19:00:13 460

原创 C++模板库STL——pair

总结:pair比较适合将两个不同类型的数据放在一块输入、输出(像一个小型结构体)0、定义与访问#include <iostream>#include <utility>#include <string>using namespace std;int main(){ pair<string,int>p; p.first = "haha...

2020-01-27 17:17:40 140

原创 C++模板库STL——stack

已经造好的轮子~0、访问(只能访问栈顶)#include <stdio.h>#include <stack>using namespace std;int main(){ stack<int>st; for(int i = 1;i <= 5;i++){ st.push(i); } printf("%d\n",st.top());//...

2020-01-27 16:50:02 109

原创 C++模板库STL——priority_queue

优先队列,在优先队列中,队首元素一定是当前队列中优先级最高的那个0、访问#include <stdio.h>#include <queue>using namespace std;int main(){ priority_queue<int>q; q.push(3); q.push(4); q.push(1); printf("%d\n",...

2020-01-27 14:48:46 147

原创 C++模板库STL——queue

STL容器是哆啦A梦的口袋~~0、queue容器内元素的访问#include <stdio.h>#include <queue>using namespace std;int main(){ queue<int>q; for(int i = 1;i <=5;i++){ q.push(i); } printf("%d %d\n",q....

2020-01-27 11:52:44 135

原创 C++模板库STL——map

感觉特别像python里的字典,emmm面向对象果然好用0、map的定义与访问代码:#include <stdio.h>#include <map>using namespace std;int main(){ map<char,int>mp; mp['c'] = 20; mp['c'] = 30;//20被覆盖 printf("%d\n...

2020-01-27 11:27:57 103

原创 (算法练习)——Least Common Multiple(最小公倍数)

要求:http://codeup.cn/problem.php?cid=100000589&pid=0说明:这一题依然是通过了本地样例,但是答案错误。。。不造为啥,有时间再看吧。。#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>...

2020-01-26 21:55:02 497

原创 (算法练习)——鸡兔同笼

要求:http://codeup.cn/problem.php?cid=100000588&pid=12说明:这一题在保存两个数的时候纠结了一会代码:#include <stdio.h>#include <math.h>#include <iostream>#include <string.h>using namespace...

2020-01-26 18:05:49 331

原创 (算法练习)——与7无关的数

要求:http://codeup.cn/problem.php?cid=100000588&pid=11说明:这一题主要注意使用c++判断是否输入结束,使用while(cin>>n)就可以了(判断cin输入是否为真)代码:#include <stdio.h>#include <iostream>#include <math.h>...

2020-01-26 15:46:37 432

原创 (算法练习)——迭代求立方根/平方根

要求:http://codeup.cn/problem.php?cid=100000588&pid=10说明:特别把这一题拿出来,这一题用递归很容易实现,but,第一次写的这个代码,没有用一个中间变量,导致超时了。。这是超时的代码:#include <stdio.h>#include <math.h> double F(int a,int b,dou...

2020-01-26 13:31:16 1465

原创 慕课学习1——C++远征之封装篇上(2020.1.25)

0、类的定义与调用(堆、栈)代码;#include <iostream>#include <stdlib.h>using namespace std;//类名最好能看出类的功能 class Coordinate{ public: int x; int y; void printX(){ cout<<x<<endl;...

2020-01-25 19:43:50 149

原创 慕课学习0:C++远征之起航篇

记录一下代码,很基础的C++介绍0、关于输入输出#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;int main(){ cout<<"请输入一个整数"<<endl; int x = 0; cin>>x;...

2020-01-25 13:23:55 1525

原创 (算法练习)——PAT A1060 Are They Equal

这两天都在刷疫情的新闻,压根没看书= =得要继续好好看书了,三月的考试一定要200+!!!!!主要是string的使用#include <stdio.h>#include <iostream>#include <string>using namespace std;int n;string deal(string s,int &e){ ...

2020-01-24 09:32:53 292

原创 C++模板库STL——string

emmmm感觉C++有点古怪又好用代码:#include <stdio.h>#include <string>#include <iostream>using namespace std;int main(){ //string的使用 string str = "abcd"; for(int i = 0;i <str.length()...

2020-01-21 18:24:58 95

原创 C++模板库STL——set

总结:set去重且递增排序代码:#include <stdio.h>#include <set>using namespace std;int main(){ //set中的数据是自动递增排序,而且去重 set<int> st; st.insert(3); st.insert(5); st.insert(2); st.insert(3...

2020-01-20 17:26:46 107

原创 C++模板库STL——vector

终于开始c++了,激动!总结:vector作为可变数组使用,可以方便统计数组中元素个数;插入、删除数据都很方便;注意删除区间的时候是左闭右开;#include <stdio.h>#include <vector>using namespace std;int main(){ vector<int> vi; for(int i = 6;i &...

2020-01-20 16:17:56 112

原创 (算法练习)——大整数运算

《算法笔记》P170乘除法没弄,书上说不常考~代码:#include <stdio.h>#include <string.h>//结构体中初始化 struct bign{ int d[1000]; int len; bign(){ memset(d,0,sizeof(d)); len = 0; }};//将str读入的数据赋值给数组 big...

2020-01-20 12:36:14 204

原创 (算法练习)——PAT A1059 Prime Factors

《算法笔记》P167求素数+结构体的使用+输出注意代码:#include <stdio.h>#include <math.h>const int maxn = 100010;//判断是否为质数 bool is_prime(int n){ if(n == 1) return false; int sqr = (int)sqrt(1.0*n); for(in...

2020-01-20 10:53:32 129

原创 (算法练习)——数素数

《算法笔记》P164代码:#include <stdio.h>const int maxn = 1000001;int prime[maxn],pNum = 0;bool p[maxn] = {0};//埃氏筛法求素数 void Find_Prime(int n){ for(int i = 2;i <maxn;i++){ if(p[i]== false){ ...

2020-01-20 10:09:34 100

原创 (算法练习)——埃氏筛法求素数

《算法笔记》P163#include <stdio.h>const int maxn = 101;int prime[maxn],pNum = 0;bool p[maxn] = {0};//埃氏筛法求素数 void Find_Prime(){ for(int i = 2;i <maxn;i++){ if(p[i]== false){ prime[pNum+...

2020-01-20 09:29:04 1451

原创 (算法练习)——开根号法求素数

《算法笔记》P162关于数学的算法题,所以本质还是数学题?代码:#include <stdio.h>#include <math.h>//判断是否为素数 bool isPrime(int n){ if(n <= 1) return false; int sqr = (int)sqrt(1.0*n); for(int i = 2;i <= sqr...

2020-01-19 21:16:01 3627

原创 (算法练习)——分数的一些计算

《算法笔记》P158把分数的加减乘除敲了一遍,算是熟悉下结构体#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;//求最大公约数的代码 int gcd(int a,int b){ if(b ==...

2020-01-19 20:24:51 388

原创 (算法练习)——数学问题->简单数学

放在一个里面:守型数:http://codeup.cn/problem.php?cid=100000588&pid=0#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;int main(){...

2020-01-19 17:08:40 393

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除