1008-09简报:手机拍摄效果可比相机(小生眼拙);学习语言应重应用而非细节 (C++作为第一语言,就开个特例,可以看一下它的细节。。。)

————— 2020-10-08 —————
0x3c 00:24

[Facepalm]我开玩笑的 你去刷leetcode多好

0x3c 00:24

从最简单题啃起

  00:25

从 KMP 算法啃起

有机后浪 00:26

[Smirk]

有机后浪 00:26

怕是kmp看到放弃哦

蓝信科技-郑君君 09:33

群主这摄影技术太厉害了

蓝信科技-郑君君 09:33

这张拍摄姿势是不是特别销魂

光城_UpUpFlink 09:35

手机放地上

————— 2020-10-09 —————

路边社 11:25

请问大家都是在哪里看招聘信息的?


礼 11:27

校招 大部分看牛客网

社招 看官网??

Mark 11:28

一些公众号也可以吧

Mark 11:28

比如校招薪水

妈,她亲我 14:45

其实,const并不能代表“常量”,它仅仅是对变量的一个修饰,告诉编译器这个变量只能被初始化,且不能被直接修改(实际上可以通过堆栈溢出等方式修改)。而这个变量的值,可以在运行时也可以在编译时指定。

妈,她亲我 14:46

这是真的假的?

妈,她亲我 15:07

https://zhuanlan.zhihu.com/c_1267952684679827456

fx 15:15

constexpr就必须在编译前指定

fx 15:16

这就是const和constexpr的区别

妈,她亲我 15:19

指定啥子

fx 15:20

[Images: Barce初始化了a(//据查a应被初始化为0); cin输入a的值;const b 用a brace初始化;(//可以) constexpr c 用a brace初始化; (//作者说会报错)]

fx 15:20

比如这个

fx 15:20

常量c在编译的时候回报错

fx 15:20

但是b就不回

fx 15:21

因为c在编译时候不知道它要初始化的值是多少

fx 15:21

所以就报错

————— 个人笔记 —————
Copy and direct initialization

One downside of assignment is that it requires at least two statements: one to define the variable, and one to assign the value.

These two steps can be combined. When a variable is defined, you can also provide an initial value for the variable at the same time. This is called initialization.

C++ supports three basic ways to initialize a variable. First, we can do copy initialization by using an equals sign:

1
int width = 5; // copy initialization of value 5 into variable width
Much like copy assignment, this copies the value on the right-hand side of the equals to the variable being created on the left-hand side.

Second, we can do direct initialization by using parenthesis.

1
int width( 5 ); // direct initialization of value 5 into variable width
For simple data types (like integers), copy and direct initialization are essentially the same. But for some advanced types, direct initialization can perform better than copy initialization. Prior to C++11, direct initialization was recommended over copy initialization in most cases because of the performance boost.

Brace initialization

Unfortunately, parenthesis-based direct initialization can’t be used for all types of initialization (such as initializing an object with a list of data). In an attempt to provide a more consistent initialization mechanism, C++11 added a new syntax called brace initialization (also sometimes called uniform initialization) that uses curly braces.

Brace initialization comes in two forms:

1
2
int width{ 5 }; // direct brace initialization of value 5 into variable width (preferred)
int height = { 6 }; // copy brace initialization of value 6 into variable height
These two forms function almost identically, but the direct form is generally preferred.

Initializing a variable with empty braces indicates zero initialization. Zero initialization generally initializes the variable to zero (or empty, if that’s more appropriate for a given type).

1
int width{}; // zero initialization to value 0
Brace initialization has the added benefit of disallowing “narrowing” conversions. This means that if you try to use brace initialization to initialize a variable with a value it can not safely hold, the compiler will throw a warning or an error. For example:

1
int width{ 4.5 }; // error: not all double values fit into an int
In the above snippet, we’re trying to assign a number (4.5) that has a fractional part (the .5 part) to an integer variable (which can only hold numbers without fractional parts). Copy and direct initialization would drop the fractional part, resulting in initialization of value 4 into variable width. However, with brace initialization, this will cause the compiler to issue an error (which is generally a good thing, because losing data is rarely desired). Conversions that can be done without potential data loss are allowed.

Author’s note

Many examples in this tutorial series were written before brace initialization existed and thus still use copy or direct initialization. We’re working on getting these updated. Please forgive our lack of adherence to best practices in this regard.
https://www.learncpp.com/cpp-tutorial/variable-assignment-and-initialization/


在计算机科学中,Knuth-Morris-Pratt字符串查找算法(简称为KMP算法)可在一个主文本字符串S内查找一个词W的出现位置。此算法通过运用对这个词在不匹配时本身就包含足够的信息来确定下一个匹配将在哪里开始的发现,从而避免重新检查先前匹配的字符。

这个算法是由高德纳和沃恩·普拉特在1974年构思,同年詹姆斯·H·莫里斯也独立地设计出该算法,最终由三人于1977年联合发表。

  • 2
  • +10番茄
  • 1694只自习生围观
  • 2020年10月10日 22:10打卡
  • 3 年,5 月前有动静
  • 引用
  • 举报
最近犒劳过的人

很巧呢。我最近也在学KMP。(其实是老师讲的啊…( _ _)ノ|我很久没有学新算法了……)

  • 亦C
  • 3 年,5 月前
  • 2020年10月11日 23:49
  • 卡主

很巧呢。我最近也在学KMP。(其实是老师讲的啊…( _ _)ノ|我很久没有学新算法了……)

天啊从语境上来看,这个算法好像很难的样子。。。加油哈

作者的近日打卡

猜你喜欢

10.11 -知识盲区:Skynet游戏引擎 硬核网课:清华的操作系统课程 -ucore操作系统 源码分析工具:SourceInsight Understand - 29岁那年,经过了一个多月的加班,连续每天只睡了,3-4个小时,晚上12点,鼻子
经验实践《一分快三全天免费计划软件快三大小倍投方案》简单小窍门77306364 - █技术探讨蔻77306364█ 邀请码30000431█GRDGYRWR汽车销量
机器学习的关键 - 我最近的理解,, 1 loss function. 比如mae 等, 2. w
  • 公达
  • ♂ 38
  • 9级
  • 自律力97.42
  • 北京
  • 程序员
方法风格 - 让坛坛罐罐
应对困难,摘录的网页 - a knack for dealing with adversity. When
应对困难,摘录的网页 - a knack for dealing with adversity. When
应对困难,摘录的网页 - a knack for dealing with adversity. When
搜索引擎精确查找,效率提升工具(原创) - 原帖:https://www.douban.com/group/topic/17
Day12 QFII、QDII、ETF、CDR,这些和跨境投资相关的缩写都是啥意思? - 一、QFII和QDII , , QFII(Qualified **Foreig
mysql事务,mvcc,并发锁机制学习 - start

合作伙伴

线上在线自习室晚自习。番茄工作法、四象限、打卡、作业清单、作业辅导、作业交流、作业跟踪、作业计划、个人宣传相关内容

行恒 © 行恒 2013