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番茄
  • 26只行者围观
  • 2020年10月10日 22:10打卡
  • 1 月,2 周前有动静
  • 引用
  • 举报
最近犒劳过的人

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

  • 亦C
  • 1 月,2 周前
  • 2020年10月11日 23:49
  • 卡主

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

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

作者的近日打卡

猜你喜欢

打卡阻挡了我开番茄的脚步,同时游街和点名怎么回事,请看今日走近科学 - rt ,
掌握Apple官方文档的使用方法 - 参考Tinyfool的文章: , http://ourcoders.com/th
发一个下电子书的好地方 - <http://it-ebooks.info/book/1441/>
  • 公达
  • 公达
  • 9级
  • 自律力96.35
  • 北京
  • 程序员
解决一个bug - #### 今天用了几个 JS 方法 , 1、$ ( this) . attr (
用积极的态度,过不完美的人生! - All success comes from tireless effort a
VyOS目前的学习材料 - Udemy: , , https://www.udemy.com/home/m
发现一个bug - rt
指责不能修复bug——出现了问题以后,首先要做的不是追究责任,而是解决问题。 - Blame doesn’t fix bugs. Instead of point
mysql事务,mvcc,并发锁机制学习 - start
尝试一下这个应用 - Just Test

免费没广告,线上在线考研高考自习室晚自习。支持番茄工作法、四象限、打卡、清单、监督、噪音检测、任务、计时、提醒休息、学习日报

行恒 © 行恒 2013