C++程序设计

原课程链接:C++程序设计 cplusplus.com 教材《新标准 c++程序设计》 郭炜, 清华大学 w11. C++11 新特性 auto 自动变量类型 decltype 关键字,求表达式类型 shared_ptr 智能指针 nullptr 空指针 基于范围的for循环 右值引用和move语义 unordered_map 无序容器(哈希表) regex 正则表达式 Lambda 表达式 强制类型转换 static_cast、interpret_cast const_cast和dynamic_cast C++异常处理基础:try、throw、catch 意外异常(unexpected exception) 动态内存管理的异常处理 new w9. STL - 质因数数目 container adapter 容器适配器 (让已有的顺序容器以栈/队列的方式工作) stack queue priority_queue member function push top pop 参考案例:github/ PKUC3/ 3.10.1.4.cpp map/ multimap map 容器中,关键字key是唯一的,值value可以重复。 multimap 容器中,关键字和值都可以重复。 set/ multiset set 容器中,元素是唯一的,按其值自动排序,而非插入顺序。 添加新对象时会比较对象的大小,set 是一个基于红黑树实现的容器,它会自动将元素按照特定的顺序存储,通常是使用元素的 < 操作符来进行比较和排序。 set 容器的迭代器支持双向迭代,可以使用++,- - 移动迭代器,但不支持随机访问,所以不能进行 i+1 的操作; ...

2024-3-12 · 8 分钟 · Atom.X

数列 Array

Week 10 array function #include<iostream> #include<cmath> using namespace std; /* looking for prime within 100. Sieve of Eratosthenes algorithm */ int main() { int sum=0, a[100]={0}; for(int i=2;i<sqrt(100.0);i++) // outer loop for i[2,9] { sum=i; while(sum<100)// inner loop for sum[2,99] { sum=sum+i; if(sum<100) a[sum]=1; // why = ? } } for(int i=2;i<100;i++) { if(a[i]==0)cout<<i<<" "; // why == ? } cout<<""<<endl; return 0; } when a[i] = {9, 15} , how could we calculate and remove it from the array a[n]? ...

2023-12-28 · 1 分钟 · Atom.X

C程序设计进阶

原课程链接:C程序设计进阶 const vs. static const 限制指针实参的功能 指针常量: 不能修改指针所指向的地址。在定义时必须立即初始化。 示例: char* const ptr = &some_char; // ptr 是一个指向 char 的常量指针 *ptr = 'a'; // 合法,修改了 ptr 所指向的 char 的值 ptr = &another_char; // 错误,不能修改 ptr 的值 常量指针: 不能修改指针所指向地址的内容,但可以改变指针所指向的地址。 示例: const char* ptr; // ptr 是一个指向 char 的常量指针 char const* ptr; // 与上一行等效 *ptr = 'a'; // 错误,不能修改 ptr 所指向的 char 的值 ptr = &another_char; // 合法,可以改变 ptr 的值 static 在函数内部或类中声明的静态变量,其生命周期跨越整个程序执行过程(在循环中多次执行,每次循环的初始值继承了上一次循环的值),且只初始化一次。 string literal #include <iostream> using namespace std; int main() { // input arguments int k=0, m=0, n=0; cin>>k; cin>>m>>" ">>n; // wrong expression. } cin operator automatically skips any whitespace, including spaces and newlines. it’s illegal to use “ ” with cin, because it is string literal, cin could not hold string. ...

2023-12-14 · 6 分钟 · Atom.X

计算导论与C语言基础

原课程链接:计算导论与C语言基础 Turing machine The ranking is in descending order of price and working speed Register: carries operation data and results, as fast as a CPU Cache: data buffer Memory: the part that cannot be placed in the CPU External memory (hard disk, USB flash drive) C. Bohm & G. Jacopini, “Flow Diagrams, Turing Machines and Languages ​​with Only Two Formations Rules”, Communications of ACM, vol9(5) May 1966, pp 366-371. Everything in the world is complicated, and there are only three kinds of logic expressed in programs: ...

2023-12-13 · 2 分钟 · Atom.X

公开课《程序设计与算法》

课程笔记 北京大学coursera 程序设计与算法 Specialization 专项课程。 练习题Github 库 作业参考GitHub - chiuchiuuu/programming-and-algorithm 课程名 以文件夹定义 C1, 计算导论与C语言基础 C2, C程序设计进阶 C3, C++程序设计 C4, 算法基础 C5, 数据结构基础 C6, 高级数据结构与算法 C7, 程序开发项目实践 文件名 取名规则:例如 2.3.3.cpp 2.C程序设计进阶 (系列课程的第二课) 3.函数递归(该课第三周) 3.编程题#4:扩号匹配问题(该周第四题) 不能保证全部代码都通过coursera或POJ的评价 Debugging case: % c++ 3.9.1.cpp 3.9.1.cpp:83:9: warning: ‘auto’ type specifier is a C++11 extension [-Wc++11-extensions] for(auto p : v) { ^ 3.9.1.cpp:83:16: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for(auto p : v) { ^ 2 warnings generated. ...

2023-12-1 · 1 分钟 · Atom.X