自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(214)
  • 资源 (1)
  • 收藏
  • 关注

原创 图片。。。。。

图片

2022-06-26 16:37:30 212

原创 linux下制作makefile文件

1.最简单的一种当然也是最麻烦的一种(makefile 中的代码如下,其中hello.cpp是文件名,hello是编译后的命名。使用方法是直接输入 make)hello:hello.cpp

2022-04-16 19:52:57 3187

原创 linux下cpp制作并使用动态库

#ifndef __MYFUNC_H#define __MYFUNC_H#include <stdio.h>#include <stdlib.h>void say_hello();int cal_sum(int x, int y);#endif #include "myfunc.hpp" ...

2022-04-15 18:53:53 800

原创 linux下cpp制作并使用静态库

linux下cpp制作并静态库

2022-04-14 22:07:37 544

原创 字母大小写的转化

#include<iostream>using namespace std;int main(){ char c1; cout<<"请输入字符:"<<endl; cin>>c1; cout<<endl; if(c1>=65&&c1<=90) printf("小写结果为:%c\n",c1+32); else if(c1>=94&&c1<=122) printf("大写结果.

2021-03-01 16:40:46 193

原创 字母大小写全排列编译实现

#include<iostream>using namespace std;#include<vector>#include<cctype>#include<string>void backTracking(vector<string> &res, string S, int i){ if (i == S.size()) { res.push_back(S); return; } if (!isalpha(S.

2020-12-23 23:00:58 171

原创 创建二叉树并层序遍历

#include<iostream>using namespace std;int const maxsize=100;typedef struct btnode{ char data; struct btnode*lchild; struct btnode*rchild;}btnode;void level(btnode *p){ int front=0; int rear=0; btnode *que[maxsize]; btnode*q; if(p!=NULL.

2020-12-23 17:52:35 130 1

原创 创建一棵二叉树并中序遍历

#include<iostream>using namespace std;typedef struct btnode{ char data; struct btnode*lchild; struct btnode*rchild;}btnode;void preorder(btnode *t){ if(t!=NULL){ preorder(t->lchild); cout<<t->data<<" "; preorder(t-&.

2020-12-23 17:25:55 678

原创 求1!+2!+3!.....+20!的和(用类实现)

#include<iostream>using namespace std;class sumjie{public: sumjie(int n){ num=n; } int sum(int num);private: int num;};int sumjie::sum(int n){ int t=1; while(n!=0) { t=t*n; n--; } return t;}int main(.

2020-12-22 23:30:47 574

原创 对称二叉树

给定一个二叉树,检查它是否是镜像对称的。递归的难点在于:找到可以递归的点 为什么很多人觉得递归一看就会,一写就废。 或者说是自己写无法写出来,关键就是你对递归理解的深不深。对于此题: 递归的点怎么找?从拿到题的第一时间开始,思路如下:1.怎么判断一棵树是不是对称二叉树? 答案:如果所给根节点,为空,那么是对称。如果不为空的话,当他的左子树与右子树对称时,他对称2.那么怎么知道左子树与右子树对不对称呢?在这我直接叫为左树和右树 答案:如果左树的左孩子与右树的右孩子对称,左树的右孩子与右树的左孩子对称,

2020-12-20 23:13:34 250

原创 判断链表中是否有环

bool hasCycle(struct ListNode *head) { if(head==NULL) return false; else{ struct ListNode *fast,*slow; fast=head->next; slow=head; while(fast!=NULL){ if(slow==fast) return true; slow=slow->next;

2020-12-20 22:36:00 107

原创 连续输入并求奇数和

#include<iostream>using namespace std;int main(){int n,m,i,key; int k=0;int sum[100];while(cin>>n){ key=1;//记录结果 for(i=0;i<n;i++) { cin>>m; if(m%2!=0){ key*=m; }}sum[k++]=key;}for(i=0;i<k;i++){ cout<<sum[i

2020-12-20 20:53:26 235

原创 ?的替换

给你一个仅包含小写英文字母和 ‘?’ 字符的字符串 s,请你将所有的 ‘?’ 转换为若干小写字母,使最终的字符串不包含任何 连续重复 的字符。注意:你 不能 修改非 ‘?’ 字符。题目测试用例保证 除 ‘?’ 字符 之外,不存在连续重复的字符。在完成所有转换(可能无需转换)后返回最终的字符串。如果有多个解决方案,请返回其中任何一个。可以证明,在给定的约束条件下,答案总是存在的。示例 1:输入:s = “?zs”输出:“azs”解释:该示例共有 25 种解决方案,从 “azs” 到 “yzs”

2020-12-19 21:55:45 356 2

原创 打家劫舍

你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。示例 1:输入:[1,2,3,1]输出:4解释:偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。偷窃到的最高金额 = 1 + 3 = 4 。int max(int a,int

2020-12-19 21:50:20 100 1

原创 搜索插入位置

给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。你可以假设数组中无重复元素。示例 1:输入: [1,3,5,6], 5输出: 2int searchInsert(int* nums, int numsSize, int target){ int i; for(i=0;i<numsSize;i++) { if(nums[i]>=target) break;

2020-12-19 21:39:11 98 1

原创 二叉树的最小深度

给定一个二叉树,找出其最小深度。最小深度是从根节点到最近叶子节点的最短路径上的节点数量。说明:叶子节点是指没有子节点的节点。int min(int a,int b){ return a>b?b:a;}int minDepth(struct TreeNode* root){ if(root==NULL) return 0; else if(root->left==NULL) return minDepth(root->right)+1;

2020-12-19 20:55:56 109 1

原创 有效的括号

给定一个只包括 ‘(’,’)’,’{’,’}’,’[’,’]’ 的字符串,判断字符串是否有效。有效字符串需满足:左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。示例 1:输入: “()”输出: truebool isValid(string s) { int n; n=s.size(); if(n%2!=0) return false; char stack[n+1];int to

2020-12-19 20:48:07 238 1

原创 排列硬币

你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币。给定一个数字 n,找出可形成完整阶梯行的总行数。n 是一个非负整数,并且在32位有符号整型的范围内。示例 1:n = 5硬币可排列成以下几行:¤¤ ¤¤ ¤因为第三行不完整,所以返回2.int arrangeCoins(int n){int i=1;while(n>=i){ n-=i; i++;}return i-1;}...

2020-12-19 20:27:15 116 2

原创 完美数

对于一个 正整数,如果它和除了它自身以外的所有 正因子 之和相等,我们称它为 「完美数」。给定一个 整数 n, 如果是完美数,返回 true,否则返回 false示例 :输入:28输出:True解释:28 = 1 + 2 + 4 + 7 + 141, 2, 4, 7, 和 14 是 28 的所有正因子。bool checkPerfectNumber(int num) { int number=0; if(num<=

2020-12-19 12:06:08 147 1

原创 平方数之和

给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c 。示例 1:输入:c = 5输出:true解释:1 * 1 + 2 * 2 = 5//要注意0也是整数 bool judgeSquareSum(int c) { int n=0; for(int i=0;i<=sqrt(c);i++) { n=c-i*i;

2020-12-19 11:58:46 146 1

原创 关于双指针的操作

1.找链表的中间节点(快指针走两步,慢指针走一步)2.找链表的倒数第k个节点(快指针先走k步,慢指针再走)3.判断链表是否成环(快指针走两步,慢指针走一步,看最终是否指向同一个节点)4.输入两个链表,找他们的第一个公共节点:定义p1,p2分别指向两个两个链表的头结点,分别往下走当p1走到链表尾部时让他指向另一个链表的头结点,p2走到链表尾部时指向另一个链表头结点,一直走到p1==p2即可...

2020-12-19 11:47:57 131 1

原创 回溯法的两种简单模版

Try(s){ for( ) //做候选者准备 { if(满足接受条件) { 1.记录next 2.if(满足结束条件) 输出结果 else Try(s+1) 3.删去next的记录 } }}void backtracking(参数){ if(满足结束条件) { 存放结果 return; } for(选择元素){ 1.处理节点 2.backtracking(参数) 3.撤销处理结果 }}

2020-12-19 11:33:20 283 1

原创 文件的使用方式

r 只读w 只写a 追加rb 只读wb 只写ab 追加

2020-12-18 17:01:37 93

原创 将数据从文件中输出

#include<iostream>#include<fstream>using namespace std;int main(){ char s; ifstream fin("字符串.txt"); if(!fin){ cout<<"文件打开失败!"<<endl; return 1; } while(!fin.eof()){ s=fin.get(); cout<<s; } cout<<endl;.

2020-12-18 16:59:15 269

原创 向文件中写入字符串

#include<iostream>using namespace std;#include<fstream>int main(){ char s[100]; gets(s); ofstream fout("字符串.txt"); if(!fout){ cout<<"文件打开失败!"<<endl; return 0; } else{ fout<<s<<endl; } return 0;}...

2020-12-18 16:58:12 1062 1

原创 共用体的应用,

有若干人员的数据,其中包括老师和学生,学生包括姓名,号码,性别,职业,班级,老师包括姓名,号码,性别,职业,职务#include<iostream>using namespace std;#include<iomanip>struct person{ int num; char name[20]; char sex; char job; union{ int clas; char position[10]; }catetory;}person[2];

2020-12-17 22:49:50 309

原创 找鞍点

鞍点:行上最大,列上最小#include <stdio.h>#define N 4#define M 5 /* 数组为4行5列 */int main(){ int i,j,k,a[N][M],max,maxj,flag; printf("please input matrix:\n"); for (i=0;i<N;i++) /* 输入数组 */ for (j=0;j<M;j++)

2020-12-17 17:33:48 117

原创 求分数序列前n项和

/*求分数序列: 2/1+3/2+5/3......的前20项和*/#include<iostream>using namespace std;double fac(double a){ if(a==1) return 1; else if(a==2) return 2; else return fac(a-1)+fac(a-2);}int main(){ double sum=0; int n=1; while(n<=20){ sum=f.

2020-12-17 17:20:34 620

原创 密码翻译

/*密码翻译: 将英文字符转化为它后边的第四个数字,区分大小写并且对于wxtz应该转化为abcd*/#include<iostream>using namespace std;int main(){ char c; while((c=getchar())!='\n'){ if((c>='a'&&c<='z')||(c>='A'&&c<='Z')){ //转化为它后边的第三个数字 c=c+4; i.

2020-12-17 17:00:59 328

原创 将上一个文件中的元素输出

#include<iostream>using namespace std;#include<fstream>#include<iomanip>struct student{ char name[20]; char sex; unsigned long birthday; float height; float weight;};int main(){ ifstream fin("student.txt"); if(!fin){ co.

2020-12-16 23:29:35 88

原创 将某宿舍两名同学的数据读入文件中

#include<iostream>using namespace std;#include<fstream> //包含头文件struct student{ char name[20]; char sex; unsigned long birthday; float height; float weight;};int main(){ student room[2]={ {"lixin",'m',19840318,1.82,65.0}, .

2020-12-16 22:42:39 94

原创 string类型的输入

#include<iostream>#include<string>using namespace std;int main(){ string s; cin>>s; //不能输入空格 getline(cin,s,'#'); //可以输入空格,遇到‘#’才会停下来 cout<<s;}

2020-12-15 19:05:29 1731

原创 多重继承

#include<iostream>using namespace std;#include<string>class teacher{ //声明教师类public: //共有部分 teacher(string nam,int a,string t){ //构造函数 name=nam; age=a; title=t; } void displayt(); //输出教师有关的数据private: .

2020-12-15 18:50:29 102

原创 类的多层派生

#include<iostream>using namespace std;#include<string>class student{public: student(int n,string nam){ num=n; name=nam; } void display();protected: int num; string name;};class student1:public student{public: student1(int n,.

2020-12-15 17:34:36 227

原创 学生类的定义

#include<iostream>using namespace std;#include<string>class student{public: student(int n,string nam,char s){ num=n; name=nam; sex=s; } void show(){ cout<<"num:"<<num<<endl; cout<<"name:"<<name<.

2020-12-15 17:15:38 554

原创 活字印刷编译实现

/*你有一套活字字模 tiles,其中每个字模上都刻有一个字母 tiles[i]。返回你可以印出的非空字母序列的数目。注意:本题中,每个活字字模只能使用一次。输入:"AAB"输出:8解释:可能的序列为 "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA"。*/#include<iostream>using namespace std;#include<vector>#include<algorithm&gt.

2020-12-13 23:45:06 145

原创 类的简单使用,两数字相加

#include <iostream> using namespace std; class Test{public: Test (int x,int y); void Sum();private: int a,b;};Test::Test(int x,int y){ a=x; b=y;}void Test::Sum(){ cout<<a+b<<endl;}int main(){ .

2020-12-13 18:52:47 245

原创 将一组数据块放到磁盘上

#include<iostream>using namespace std;#include<cstdio>struct student{ char name[10]; int num; int age; char addr[10];}stu[2];void save(){ FILE *fp; int i; if((fp=fopen("stu.dat","wb"))==NULL) { cout<<"打开文件失败:"<<en.

2020-12-13 17:51:17 105

原创 fputs函数和fgets函数的使用/*

/* fputs(s[],fp)函数的使用!*/#include<stdio.h>#include<iostream>using namespace std;int main(){ FILE *fp; if((fp=fopen("fputs.txt","w"))==NULL){ cout<<"文件打开失败:"<<endl; return 0; } else { char s[20]; gets(s); fputs(.

2020-12-13 16:41:27 237

原创 将一个文件中的数据复制到另一个文件中

/* 将一个磁盘中的文件,复制到另一个磁盘文件中,*/#include<iostream>using namespace std;#include<stdio.h>int main(){ FILE *in,*out; char ch,infile[10],outfile[10]; cout<<"请输入读入文件的名字:"<<endl; gets(infile); cout<<"请输入输出文件...

2020-12-13 16:25:59 970

蓝桥云课。。。。。。。。。。。。。。。

蓝桥云课。。。。。。。。。。。。。。。

2022-06-26

空空如也

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

TA关注的人

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