c++
Runner1st
这个作者很懒,什么都没留下…
展开
-
static在C++中的一些用法
static在C++中的一些用法:static是与auto相对的一个关键字,我们平时没有用static修饰的变量,都是默认为auto的。所以要理解static,就先看看auto。auto(automatic)的含义是由程序自动控制变量的生存周期,通常指的就是变量在进入其作用域的时候被分配内存,离开其作用域的时候被释放; 而static是变量在程序初始化时被分配,直到程序退出前才被释放。在C++中的原创 2016-11-20 17:21:40 · 544 阅读 · 1 评论 -
数据结构——栈
文章目录1. 概念2. 初体验3. 栈的实现3.1 Contiguous Stack3.2 Linked Stack4. 相关算法4.1 括号匹配4.2 铁道交换网4.3 逆波兰计算器(a reverse Polish calculator)1. 概念栈(stack)是一种形式的表,在这种数据结构中,所有的元素插入和删除都在表的一端进行,这一端称为栈顶(top)。向栈中增加一项时,叫入栈(pu...原创 2019-03-04 21:48:11 · 250 阅读 · 0 评论 -
DES算法C++程序设计和实现
文章目录1 算法原理概述2 总体结构3 模块分解4 数据结构5 编译运行结果6 源代码1 算法原理概述Data Encryption Standard (DES) 是一种典型的对称密钥算法,采用块加密方法,它以64位为分组长度,64位一组的明文作为算法的输入,通过与密钥运算和一系列复杂的操作,输出同样64位长度的密文,用同一密钥可以解密,所以该算法所有的保密性依赖于密钥,认为只有持有加密所用的...原创 2019-03-02 11:36:42 · 3416 阅读 · 4 评论 -
MD算法C++程序设计和实现
文章目录1 算法原理概述2 总体结构3 模块分解3.1 填充及分块模块3.2 初始化模块3.3 循环压缩模块3.4 整数转字符串模块3.5 获取MD5模块(总)3.6 输入模块3.7 输出模块4 数据结构4.1 MD5类4.2 unsigned int5 编译运行结果6 源代码1 算法原理概述MD5,即Message-Digest Algorithm 5 (信息-摘要算法5),是广泛使用的Ha...原创 2019-03-02 11:46:43 · 1554 阅读 · 0 评论 -
数字证书结构描述+解析的C程序设计和实现
文章目录1 X.509 证书结构描述1.1 整体结构1.2 证书内容1.3 编码2 源代码3 编译运行结果1 X.509 证书结构描述1.1 整体结构证书内容、签名算法、签名结果。tbsCertificateTBSCertificatesignatureAlgorithmAlgorithmIdentifiersignatureValueBIT STRING...原创 2019-03-02 12:03:25 · 2482 阅读 · 5 评论 -
c语言指针的基本使用
文章目录指针变量的定义和初始化指针操作按引用向函数传递参数const 修饰符sizeof 操作符指针表达式和指针运算指针数组函数指针指针(pointer)是C语言中一个重点和难点,以下是对其基本使用的一些总结,适合入门的同学。除了是对自己的学习的总结之外,也希望能对大家有所帮助。指针变量的定义和初始化与C语言其他变量类似,指针也是一种变量,只不过它与其他变量不同,一般变量是直接包含了一个特定...原创 2019-03-03 13:15:45 · 4447 阅读 · 0 评论 -
C++中关于使用[]定义的静态数组和new分配的动态数组的区别
静态数组:int a[20];int b[] = {1, 2, 3}静态数组的长度为常量,在栈中分配内存空间,会自动释放。使用sizeof时,计算的是整个数组的字节大小。动态数组:int len = 20;int *a = new int[len];delete a;动态数组在堆中分配内存,必须手动释放。使用sizeof时,计算的是指针变量所占内存的字节大小。在使...原创 2019-03-03 13:36:40 · 1814 阅读 · 0 评论 -
<Sicily>1001. Rails
原题如下1001. RailsTime Limit: 1sec Memory Limit:32MBDescriptionThere is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortun...原创 2019-03-04 21:29:14 · 199 阅读 · 0 评论 -
判断一颗树是不是另一棵树的子结构
问题输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)思路及实现首先要明确的一点是,子结构不是子树,子树是一个更强的条件,而子结构只是指树结构中有这一子部分,如下图,B不是A的子树,但却是A的子结构。 1 2 / \ \ 2 3 5 / \ \...原创 2019-03-23 15:40:15 · 682 阅读 · 0 评论 -
<Sicily>1005. Prime Palindromes质数回文数的判断方法
原题如下Time Limit: 1sec Memory Limit:256MBDescriptionThe number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). W...原创 2019-03-24 09:33:37 · 371 阅读 · 0 评论 -
动态规划——最大连乘子序列
昨天去富途面试实习生的时候问到了这样的一道题,记录一下。题目求出一串数的最大连乘子序列的乘积。所谓最大连乘子序列,就是指连续的子序列中的乘积最大的那个子序列,比如{-2.5, 3, 0, 2, 4, -6, -2},24(-6)*(-2)就是乘积最大的连续子序列,结果为96。思路一循环暴力破解法,就是穷举所有的子串,然后求出乘积最大的那个,时间复杂度为O(n2)O(n^2)O(n2)。思...原创 2019-03-29 11:23:46 · 378 阅读 · 0 评论 -
c++模板与泛型编程
文章目录1 定义模板1.1 函数模板1.2 类模板1.3 模板参数1.4 成员模板1.5 控制实例化1.6 效率与灵活性2 模板实参推断2.1 类型转换与模板类型参数2.2 函数模板显式实参2.3 尾置返回类型与类型转换2.4 函数指针和实参推断1 定义模板1.1 函数模板template <typename T> // 模板参数列表,不能为空,用逗号隔开,每个类型参数前必须使用...原创 2019-07-31 18:42:18 · 275 阅读 · 0 评论 -
<Sicily>1000. 数字反转
原题如下Description给定一个整数,请将该数各个位上数字反转得到一个新数。新数也应满足整数的常见形式,即除非给定的原数为零,否则反转后得到的新数的最高位数字不应为零(参见样例2)。Input输入共 1 行,一个整数N。-1,000,000,000 ≤ N≤ 1,000,000,000。Output输出共 1 行,一个整数,表示反转后的新数。Sample Input样例1:...原创 2019-01-12 17:12:06 · 224 阅读 · 0 评论 -
LeetCode404. Sum of Left Leaves所有左叶节点的和 #算法# 第十四周
原题Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24....原创 2018-12-09 19:27:22 · 190 阅读 · 0 评论 -
计算不含重复字符的最长子串的长度 #算法#
原题如下:Given a string, find the length of the longest substring without repeating characters.给出一个字符串,计算没有重复字符的最长子串的长度。Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", w...原创 2018-09-25 16:05:17 · 2379 阅读 · 0 评论 -
Online Stock Span 库存价格持续时间计算 #算法#
原题如下:Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock’s price for the current day.The span of the stock’s price today is defined as t...原创 2018-09-22 09:03:21 · 287 阅读 · 0 评论 -
根据前序和中序(后序和中序)遍历构造树 #算法#
原题如下Given preorder and inorder traversal of a tree, construct the binary tree.根据前序和中序遍历序列构建二叉树。Note:You may assume that duplicates do not exist in the tree.For example, givenpreorder = [3,9,20,1...原创 2018-10-12 20:35:13 · 434 阅读 · 0 评论 -
sameTree用深度优先搜索判断两棵树是否相同 #算法#
Given two binary trees, write a function to check if they are the same or not.给定两个二叉树,写一个函数检查它们是否相同。Two binary trees are considered the same if they are structurally identical and the nodes have the...原创 2018-10-07 18:42:27 · 252 阅读 · 0 评论 -
Fruit Into Baskets #算法#
原题如下In a row of trees, the i-th tree produces fruit with type tree[i].有一行树,第i棵树产出tree[i]类型的水果。You start at any tree of your choice, then repeatedly perform the following steps:Add one piece of fru...原创 2018-10-21 17:36:34 · 260 阅读 · 0 评论 -
leetcode 110-判断一棵树是否为平衡二叉树 #算法#
原题如下Given a binary tree, determine if it is height-balanced.给出一棵二叉树,判断它是否高度平衡。For this problem, a height-balanced binary tree is defined as:高度平衡二叉树定义为:a binary tree in which the depth of the two ...原创 2018-10-27 20:03:59 · 820 阅读 · 0 评论 -
LeetCode111. Minimum Depth of Binary Tree二叉树的最小深度 #算法# 第九周
原题如下Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no chil...原创 2018-11-05 22:32:11 · 128 阅读 · 0 评论 -
LeetCode112. Path Sum判断二叉树是否存在一条总值为sum的路径 #算法# 第十周
原题如下Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.给定一棵二叉树和sum,判断是否存在这样的一条从根到叶子的路径,它的路径上的值的总和等于su...原创 2018-11-13 19:15:39 · 266 阅读 · 0 评论 -
LeetCode113. Path Sum II 找出二叉树中总值为sum的所有路径 #算法# 第十一周
原题如下Given a binary tree and a sum, find all root-to-leaf paths where each path’s sum equals the given sum.Note: A leaf is a node with no children.Example:Given the below binary tree and sum = 22,...原创 2018-11-13 20:40:37 · 225 阅读 · 0 评论 -
LeetCode367. Valid Perfect Square判断是否为完全平方数 #算法# 第十二周
原题Given a positive integer num, write a function which returns True if num is a perfect square else False.给出一个正整数,写一个函数,若该数为完全平方数,则返回True;否则返回False。Note: Do not use any built-in library function su...原创 2018-12-02 18:35:16 · 219 阅读 · 0 评论 -
LeetCode374. Guess Number Higher or Lower猜数 #算法# 第十三周
原题We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I’ll tell you whether the number is higher o...原创 2018-12-02 19:39:09 · 1001 阅读 · 0 评论 -
windows 下 socket 的 shutdown 和 closesocket 的区别
It is important to distinguish the difference between shutting down a socket connection and closing a socket.分辨关闭(shutdown)一个socket连接和关闭一个socket的区别是重要的。以下为了区分二者,分别用英文的shutdown和close表述。shutdown a ...原创 2019-08-29 12:09:05 · 2056 阅读 · 0 评论