随笔分类 -  C++

摘要:# [4\. 寻找两个正序数组的中位数](https://leetcode.cn/problems/median-of-two-sorted-arrays/) 给定两个大小分别为 `m` 和 `n` 的正序(从小到大)数组 `nums1` 和 `nums2`。请你找出并返回这两个正序数组的 **中位 阅读全文
posted @ 2023-05-24 22:12 Revc 阅读(20) 评论(0) 推荐(0) 编辑
摘要:# 前言 C++ 定义了丰富的抽象数据类型。 `string` 支持变长字符串。 `vector` 支持变长集合。 迭代器用于访问容器中的元素,比如,`string` 中的字符和`vector` 中的元素。 `string` 和 `vector` 都基于更加原始的数组类型。 # 使用 using 声 阅读全文
posted @ 2023-05-21 19:40 Revc 阅读(103) 评论(0) 推荐(0) 编辑
摘要:简单来说 Class 是一种 Type。 A class is a type. Its name becomes a class-name ([class.name]) within its scope. 来自 C++ Draft int, char 等是基本类型。 Class 是复合类型或自定义类 阅读全文
posted @ 2023-05-07 23:22 Revc 阅读(145) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <vector> int main() { std::vector<int> arr = {1, 2, 3}; const int &a = arr[0]; std::cout << a << '\n'; arr.erase(arr.begi 阅读全文
posted @ 2023-05-07 23:12 Revc 阅读(22) 评论(0) 推荐(0) 编辑
摘要:Exercise 2.1 Questions What are the differences between int, long, long long, and short? Between an unsigned and a signed type? Between a float and a 阅读全文
posted @ 2023-05-03 21:54 Revc 阅读(220) 评论(0) 推荐(0) 编辑
摘要:一些语言的公共特性 内建类型,如整型,字符型等; 变量,为值绑定的一个名字; 表达式和语句,操作值。 分支和循环,允许我们条件执行和重复执行; 函数,定义抽象计算单元。 扩展语言的方式 自定义类型; 标准库。 本章重点 学习语言的基本知识和标准库。 内建类型; 简要介绍自定义类。 类型 定义了数据的 阅读全文
posted @ 2023-05-03 21:54 Revc 阅读(35) 评论(0) 推荐(0) 编辑
摘要:这两种写法效率依赖处理器、编译器和标准库。一般来说循环内的重复操作的性能差于循环外的单次操作。 参考文献 Which is more efficient to use in a for loop, i<sqrt(n) or i*i<(n)? 阅读全文
posted @ 2023-03-06 19:21 Revc 阅读(46) 评论(0) 推荐(0) 编辑
摘要:true == 1; true + 1; If the destination type is bool, see 4.12. If the source type is bool, the value false is converted to zero and the value true is 阅读全文
posted @ 2023-03-06 19:04 Revc 阅读(39) 评论(0) 推荐(0) 编辑
摘要:for (int i = 0; i < buildings.size(); i++) {} 和 int n = buildings.size(); for (int i = 0; i < n; i++) {} 之间的效率差距如何? 通常 size() 函数的调用会被编译器内联,可能会有些许性能损失, 阅读全文
posted @ 2023-03-06 18:51 Revc 阅读(33) 评论(0) 推荐(0) 编辑
摘要:如果存在如下的输入, 11 is a prime 考虑如下的程序, std::cin>>number; std::getline(std::cin,input) std::cin 在读取数字 11 时,没有读取 11 后面的换行符。这个换行符被之后的 std::getline 消耗了,从而导致 st 阅读全文
posted @ 2023-03-05 22:49 Revc 阅读(123) 评论(0) 推荐(0) 编辑
摘要:C 语言中的 % 是余数操作符,而==不是==模数操作符。 模数被定义为 k := n - d*q,q 是一个整数使得 k 的符号和 d 的符号一致,同时使得 k 的绝对值尽可能的小。 余数被定义为 k := n - (n/d)*d,k 的符号和 n 一致。 参考资料 Remainder Modul 阅读全文
posted @ 2023-03-05 22:38 Revc 阅读(121) 评论(0) 推荐(0) 编辑
摘要:std::cout << std::endl; 等价于 std::cout << '\n' << std::flush; 除了写入换行符,std::endl 还会刷新缓冲区。除非程序对于性能十分敏感,不然使用 \n 或者 std::end 差别不大。 参考资料 What’s the differen 阅读全文
posted @ 2023-03-05 22:11 Revc 阅读(59) 评论(0) 推荐(0) 编辑
摘要:学习方法 The way to learn a new programming language is to write programs. 学习一门新编程语言的方式是编写程序。 函数(Function) 函数的四部分: 返回类型; 函数名; 参数列表; 函数体。 main 函数返回值(Return 阅读全文
posted @ 2023-02-04 23:00 Revc 阅读(88) 评论(0) 推荐(0) 编辑
摘要:机器效率和编程效率 Its focus, and that of its programming community, has widened from looking mostly at machine efficiency to devoting more attention to program 阅读全文
posted @ 2023-02-03 23:52 Revc 阅读(36) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示