From 0f648593cb6aba53ae60937ef3a0ed09119f6d3f Mon Sep 17 00:00:00 2001 From: "yinghui.cai" Date: Thu, 8 Jan 2026 22:00:38 +0800 Subject: [PATCH 1/2] 11 --- exercises/00_hello_world/main.cpp | 2 +- exercises/01_variable&add/main.cpp | 1 + exercises/02_function/main.cpp | 8 ++-- exercises/03_argument¶meter/main.cpp | 8 ++-- exercises/04_static/main.cpp | 10 ++--- exercises/05_constexpr/main.cpp | 2 +- exercises/06_array/main.cpp | 4 +- exercises/07_loop/main.cpp | 5 ++- exercises/08_pointer/main.cpp | 5 +++ exercises/09_enum&union/main.cpp | 2 +- exercises/10_trivial/main.cpp | 9 +++-- exercises/11_method/main.cpp | 6 ++- exercises/12_method_const/main.cpp | 3 +- exercises/13_class/main.cpp | 4 +- exercises/14_class_destruct/main.cpp | 11 ++++-- exercises/15_class_clone/main.cpp | 18 +++++++-- exercises/16_class_move/main.cpp | 27 ++++++++++--- exercises/17_class_derive/main.cpp | 6 +-- exercises/18_class_virtual/main.cpp | 40 ++++++++++---------- exercises/19_class_virtual_destruct/main.cpp | 21 +++++----- exercises/29_std_map/main.cpp | 2 + exercises/31_std_shared_ptr/main.cpp | 18 ++++----- exercises/32_std_transform/main.cpp | 3 ++ exercises/33_std_accumulate/main.cpp | 2 + exercises/wget-log | 22 +++++++++++ exercises/wget-log.1 | 13 +++++++ exercises/wget-log.10 | 12 ++++++ exercises/wget-log.11 | 28 ++++++++++++++ exercises/wget-log.2 | 12 ++++++ exercises/wget-log.3 | 28 ++++++++++++++ exercises/wget-log.4 | 22 +++++++++++ exercises/wget-log.5 | 10 +++++ exercises/wget-log.6 | 28 ++++++++++++++ exercises/wget-log.7 | 12 ++++++ exercises/wget-log.8 | 22 +++++++++++ exercises/wget-log.9 | 10 +++++ wget-log | 22 +++++++++++ wget-log.1 | 13 +++++++ wget-log.10 | 12 ++++++ wget-log.11 | 28 ++++++++++++++ wget-log.2 | 28 ++++++++++++++ wget-log.3 | 15 ++++++++ wget-log.4 | 22 +++++++++++ wget-log.5 | 12 ++++++ wget-log.6 | 28 ++++++++++++++ wget-log.7 | 10 +++++ wget-log.8 | 22 +++++++++++ wget-log.9 | 10 +++++ 48 files changed, 579 insertions(+), 79 deletions(-) create mode 100644 exercises/wget-log create mode 100644 exercises/wget-log.1 create mode 100644 exercises/wget-log.10 create mode 100644 exercises/wget-log.11 create mode 100644 exercises/wget-log.2 create mode 100644 exercises/wget-log.3 create mode 100644 exercises/wget-log.4 create mode 100644 exercises/wget-log.5 create mode 100644 exercises/wget-log.6 create mode 100644 exercises/wget-log.7 create mode 100644 exercises/wget-log.8 create mode 100644 exercises/wget-log.9 create mode 100644 wget-log create mode 100644 wget-log.1 create mode 100644 wget-log.10 create mode 100644 wget-log.11 create mode 100644 wget-log.2 create mode 100644 wget-log.3 create mode 100644 wget-log.4 create mode 100644 wget-log.5 create mode 100644 wget-log.6 create mode 100644 wget-log.7 create mode 100644 wget-log.8 create mode 100644 wget-log.9 diff --git a/exercises/00_hello_world/main.cpp b/exercises/00_hello_world/main.cpp index 8866f3c15..2272a39ab 100644 --- a/exercises/00_hello_world/main.cpp +++ b/exercises/00_hello_world/main.cpp @@ -6,6 +6,6 @@ int main(int argc, char **argv) { // TODO: 在控制台输出 "Hello, InfiniTensor!" 并换行 - std::cout : "Hello, InfiniTensor!" + std::endl; + std::cout <<"Hello, InfiniTensor!" << std::endl; return 0; } diff --git a/exercises/01_variable&add/main.cpp b/exercises/01_variable&add/main.cpp index 5014863fd..52c6281d5 100644 --- a/exercises/01_variable&add/main.cpp +++ b/exercises/01_variable&add/main.cpp @@ -5,6 +5,7 @@ int main(int argc, char **argv) { // TODO: 补全变量定义并打印加法运算 // x ? + int x = 42; std::cout << x << " + " << x << " = " << x + x << std::endl; return 0; } diff --git a/exercises/02_function/main.cpp b/exercises/02_function/main.cpp index b5eef7f28..5af419564 100644 --- a/exercises/02_function/main.cpp +++ b/exercises/02_function/main.cpp @@ -5,6 +5,11 @@ // NOTICE: 补充由内而外读法的机翻解释 // TODO: 在这里声明函数 +int add(int a, int b) { + // TODO: 补全函数定义,但不要移动代码行 + return a + b; +} + int main(int argc, char **argv) { ASSERT(add(123, 456) == 123 + 456, "add(123, 456) should be 123 + 456"); @@ -14,6 +19,3 @@ int main(int argc, char **argv) { return 0; } -int add(int a, int b) { - // TODO: 补全函数定义,但不要移动代码行 -} diff --git a/exercises/03_argument¶meter/main.cpp b/exercises/03_argument¶meter/main.cpp index 7fb5d3c2f..76136eae6 100644 --- a/exercises/03_argument¶meter/main.cpp +++ b/exercises/03_argument¶meter/main.cpp @@ -8,19 +8,19 @@ void func(int); // TODO: 为下列 ASSERT 填写正确的值 int main(int argc, char **argv) { auto arg = 99; - ASSERT(arg == ?, "arg should be ?"); + ASSERT(arg == 99, "arg should be ?"); std::cout << "befor func call: " << arg << std::endl; func(arg); - ASSERT(arg == ?, "arg should be ?"); + ASSERT(arg == 99, "arg should be ?"); std::cout << "after func call: " << arg << std::endl; return 0; } // TODO: 为下列 ASSERT 填写正确的值 void func(int param) { - ASSERT(param == ?, "param should be ?"); + ASSERT(param == 99, "param should be ?"); std::cout << "befor add: " << param << std::endl; param += 1; - ASSERT(param == ?, "param should be ?"); + ASSERT(param == 100, "param should be ?"); std::cout << "after add: " << param << std::endl; } diff --git a/exercises/04_static/main.cpp b/exercises/04_static/main.cpp index f107762fa..64f417694 100644 --- a/exercises/04_static/main.cpp +++ b/exercises/04_static/main.cpp @@ -10,10 +10,10 @@ static int func(int param) { int main(int argc, char **argv) { // TODO: 将下列 `?` 替换为正确的数字 - ASSERT(func(5) == ?, "static variable value incorrect"); - ASSERT(func(4) == ?, "static variable value incorrect"); - ASSERT(func(3) == ?, "static variable value incorrect"); - ASSERT(func(2) == ?, "static variable value incorrect"); - ASSERT(func(1) == ?, "static variable value incorrect"); + ASSERT(func(5) == 5, "static variable value incorrect"); + ASSERT(func(4) == 6, "static variable value incorrect"); + ASSERT(func(3) == 7, "static variable value incorrect"); + ASSERT(func(2) == 8, "static variable value incorrect"); + ASSERT(func(1) == 9, "static variable value incorrect"); return 0; } diff --git a/exercises/05_constexpr/main.cpp b/exercises/05_constexpr/main.cpp index d1db6c9d8..faf144b74 100644 --- a/exercises/05_constexpr/main.cpp +++ b/exercises/05_constexpr/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char **argv) { // TODO: 观察错误信息,修改一处,使代码编译运行 // PS: 编译运行,但是不一定能算出结果…… - constexpr auto ANS_N = 90; + constexpr auto ANS_N = 40; constexpr auto ANS = fibonacci(ANS_N); std::cout << "fibonacci(" << ANS_N << ") = " << ANS << std::endl; diff --git a/exercises/06_array/main.cpp b/exercises/06_array/main.cpp index 61ed99ec0..eaeb33c38 100644 --- a/exercises/06_array/main.cpp +++ b/exercises/06_array/main.cpp @@ -11,13 +11,13 @@ unsigned long long fibonacci(int i) { return 1; default: // TODO: 补全三目表达式缺失的部分 - return ? : (arr[i] = fibonacci(i - 1) + fibonacci(i - 2)); + return i >=80 ? 23416728348467685 : (arr[i] = fibonacci(i - 1) + fibonacci(i - 2)); } } int main(int argc, char **argv) { // TODO: 为此 ASSERT 填写正确的值 - ASSERT(sizeof(arr) == ?, "sizeof array is size of all its elements"); + ASSERT(sizeof(arr) == 90 * sizeof(unsigned long long), "sizeof array is size of all its elements"); // ---- 不要修改以下代码 ---- ASSERT(fibonacci(2) == 1, "fibonacci(2) should be 1"); ASSERT(fibonacci(20) == 6765, "fibonacci(20) should be 6765"); diff --git a/exercises/07_loop/main.cpp b/exercises/07_loop/main.cpp index 44fd835cd..80b8e9868 100644 --- a/exercises/07_loop/main.cpp +++ b/exercises/07_loop/main.cpp @@ -6,8 +6,11 @@ static unsigned long long fibonacci(int i) { // TODO: 为缓存设置正确的初始值 static unsigned long long cache[96], cached; + cache[0] = 0; + cache[1] = 1; + cached = 2; // TODO: 设置正确的循环条件 - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; diff --git a/exercises/08_pointer/main.cpp b/exercises/08_pointer/main.cpp index ba37173f5..85f3a3401 100644 --- a/exercises/08_pointer/main.cpp +++ b/exercises/08_pointer/main.cpp @@ -5,6 +5,11 @@ bool is_fibonacci(int *ptr, int len, int stride) { ASSERT(len >= 3, "`len` should be at least 3"); // TODO: 编写代码判断从 ptr 开始,每 stride 个元素取 1 个元素,组成长度为 n 的数列是否满足 // arr[i + 2] = arr[i] + arr[i + 1] + for(int i = 0; i <= len-3 ; i++) { + if( *(ptr + (i + 2) * stride) != *(ptr + i * stride) + *(ptr + (i + 1) * stride) ) { + return false; + } + } return true; } diff --git a/exercises/09_enum&union/main.cpp b/exercises/09_enum&union/main.cpp index 3f2cec768..ead91762d 100644 --- a/exercises/09_enum&union/main.cpp +++ b/exercises/09_enum&union/main.cpp @@ -37,7 +37,7 @@ ColorEnum convert_by_pun(Color c) { TypePun pun; // TODO: 补全类型双关转换 - + pun.c = c; return pun.e; } diff --git a/exercises/10_trivial/main.cpp b/exercises/10_trivial/main.cpp index 6ba23e48e..567c8b33a 100644 --- a/exercises/10_trivial/main.cpp +++ b/exercises/10_trivial/main.cpp @@ -9,10 +9,10 @@ struct FibonacciCache { // TODO: 实现正确的缓存优化斐波那契计算 static unsigned long long fibonacci(FibonacciCache &cache, int i) { - for (; false; ++cached) { - cache[cached] = cache[cached - 1] + cache[cached - 2]; + for (; cache.cached <= i; cache.cached++) { + cache.cache[cache.cached] = cache.cache[cache.cached - 1] + cache.cache[cache.cached - 2]; } - return cache.cache[i]; + return cache.cache[cache.cached - 1]; } int main(int argc, char **argv) { @@ -20,6 +20,9 @@ int main(int argc, char **argv) { // NOTICE: C/C++ 中,读取未初始化的变量(包括结构体变量)是未定义行为 // READ: 初始化的各种写法 FibonacciCache fib; + fib.cache[0] = 0; + fib.cache[1] = 1; + fib.cached = 2; ASSERT(fibonacci(fib, 10) == 55, "fibonacci(10) should be 55"); std::cout << "fibonacci(10) = " << fibonacci(fib, 10) << std::endl; return 0; diff --git a/exercises/11_method/main.cpp b/exercises/11_method/main.cpp index 0e08e0a36..d5ceced3d 100644 --- a/exercises/11_method/main.cpp +++ b/exercises/11_method/main.cpp @@ -6,7 +6,7 @@ struct Fibonacci { // TODO: 实现正确的缓存优化斐波那契计算 unsigned long long get(int i) { - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; @@ -16,6 +16,10 @@ struct Fibonacci { int main(int argc, char **argv) { // TODO: 初始化缓存结构体,使计算正确 Fibonacci fib; + fib.cache[0] = 0; + fib.cache[1] = 1; + fib.cached = 2; + ASSERT(fib.get(10) == 55, "fibonacci(10) should be 55"); std::cout << "fibonacci(10) = " << fib.get(10) << std::endl; return 0; diff --git a/exercises/12_method_const/main.cpp b/exercises/12_method_const/main.cpp index 5521be4da..65c079be1 100644 --- a/exercises/12_method_const/main.cpp +++ b/exercises/12_method_const/main.cpp @@ -5,7 +5,8 @@ struct Fibonacci { int numbers[11]; // TODO: 修改方法签名和实现,使测试通过 - int get(int i) { + int get(int i) const { + return numbers[i]; } }; diff --git a/exercises/13_class/main.cpp b/exercises/13_class/main.cpp index 9afa98c5b..b53da318d 100644 --- a/exercises/13_class/main.cpp +++ b/exercises/13_class/main.cpp @@ -15,10 +15,10 @@ class Fibonacci { public: // TODO: 实现构造器 // Fibonacci() - + Fibonacci() : cache{0, 1}, cached(2) {} // TODO: 实现正确的缓存优化斐波那契计算 size_t get(int i) { - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; diff --git a/exercises/14_class_destruct/main.cpp b/exercises/14_class_destruct/main.cpp index 42150e8ca..e6dd85b59 100644 --- a/exercises/14_class_destruct/main.cpp +++ b/exercises/14_class_destruct/main.cpp @@ -11,14 +11,19 @@ class DynFibonacci { public: // TODO: 实现动态设置容量的构造器 - DynFibonacci(int capacity): cache(new ?), cached(?) {} + DynFibonacci(int capacity): cache(new size_t[capacity]), cached(2) { + cache[0] = 0; + cache[1] = 1; + } // TODO: 实现析构器,释放缓存空间 - ~DynFibonacci(); + ~DynFibonacci() { + delete[] cache; + } // TODO: 实现正确的缓存优化斐波那契计算 size_t get(int i) { - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; diff --git a/exercises/15_class_clone/main.cpp b/exercises/15_class_clone/main.cpp index f74b70391..54f4ce789 100644 --- a/exercises/15_class_clone/main.cpp +++ b/exercises/15_class_clone/main.cpp @@ -7,20 +7,30 @@ class DynFibonacci { size_t *cache; int cached; + int capacity; public: // TODO: 实现动态设置容量的构造器 - DynFibonacci(int capacity): cache(new ?), cached(?) {} + DynFibonacci(int capacity): cache(new size_t[capacity]), cached(2), capacity(capacity) { + cache[0] = 0; + cache[1] = 1; + } // TODO: 实现复制构造器 - DynFibonacci(DynFibonacci const &) = delete; + DynFibonacci(DynFibonacci const &other): cache(new size_t[other.capacity]), cached(other.cached), capacity(other.capacity) { + for (int i = 0; i < other.cached;++i){ + cache[i] = other.cache[i]; + } + } // TODO: 实现析构器,释放缓存空间 - ~DynFibonacci(); + ~DynFibonacci(){ + delete[] cache; + }; // TODO: 实现正确的缓存优化斐波那契计算 size_t get(int i) { - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; diff --git a/exercises/16_class_move/main.cpp b/exercises/16_class_move/main.cpp index 8d2c421da..ef5687be9 100644 --- a/exercises/16_class_move/main.cpp +++ b/exercises/16_class_move/main.cpp @@ -15,21 +15,38 @@ class DynFibonacci { public: // TODO: 实现动态设置容量的构造器 - DynFibonacci(int capacity): cache(new ?), cached(?) {} + DynFibonacci(int capacity): cache(new size_t[capacity]), cached(2) { + cache[0] = 0; + cache[1] = 1; + } // TODO: 实现移动构造器 - DynFibonacci(DynFibonacci &&) noexcept = delete; + DynFibonacci(DynFibonacci &&other) : cache(other.cache), cached(other.cached) { + other.cache = nullptr; + other.cached = 0; + } // TODO: 实现移动赋值 // NOTICE: ⚠ 注意移动到自身问题 ⚠ - DynFibonacci &operator=(DynFibonacci &&) noexcept = delete; + DynFibonacci &operator=(DynFibonacci &&other) noexcept { + if (this != &other){ + delete[] cache; + cache = other.cache; + cached = other.cached; + other.cache = nullptr; + other.cached = 0; + } + return *this; + } // TODO: 实现析构器,释放缓存空间 - ~DynFibonacci(); + ~DynFibonacci(){ + delete[] cache; + } // TODO: 实现正确的缓存优化斐波那契计算 size_t operator[](int i) { - for (; false; ++cached) { + for (; cached <= i; ++cached) { cache[cached] = cache[cached - 1] + cache[cached - 2]; } return cache[i]; diff --git a/exercises/17_class_derive/main.cpp b/exercises/17_class_derive/main.cpp index 819ae72fc..befa0ed7d 100644 --- a/exercises/17_class_derive/main.cpp +++ b/exercises/17_class_derive/main.cpp @@ -50,9 +50,9 @@ int main(int argc, char **argv) { B b = B(3); // TODO: 补全三个类型的大小 - static_assert(sizeof(X) == ?, "There is an int in X"); - static_assert(sizeof(A) == ?, "There is an int in A"); - static_assert(sizeof(B) == ?, "B is an A with an X"); + static_assert(sizeof(X) == sizeof(int), "There is an int in X"); + static_assert(sizeof(A) == sizeof(int), "There is an int in A"); + static_assert(sizeof(B) == sizeof(A) + sizeof(X), "B is an A with an X"); i = 0; std::cout << std::endl diff --git a/exercises/18_class_virtual/main.cpp b/exercises/18_class_virtual/main.cpp index ac6382413..344709e4c 100644 --- a/exercises/18_class_virtual/main.cpp +++ b/exercises/18_class_virtual/main.cpp @@ -42,38 +42,38 @@ int main(int argc, char **argv) { C c; D d; - ASSERT(a.virtual_name() == '?', MSG); - ASSERT(b.virtual_name() == '?', MSG); - ASSERT(c.virtual_name() == '?', MSG); - ASSERT(d.virtual_name() == '?', MSG); - ASSERT(a.direct_name() == '?', MSG); - ASSERT(b.direct_name() == '?', MSG); - ASSERT(c.direct_name() == '?', MSG); - ASSERT(d.direct_name() == '?', MSG); + ASSERT(a.virtual_name() == 'A', MSG); + ASSERT(b.virtual_name() == 'B', MSG); + ASSERT(c.virtual_name() == 'C', MSG); + ASSERT(d.virtual_name() == 'C', MSG); + ASSERT(a.direct_name() == 'A', MSG); + ASSERT(b.direct_name() == 'B', MSG); + ASSERT(c.direct_name() == 'C', MSG); + ASSERT(d.direct_name() == 'D', MSG); A &rab = b; B &rbc = c; C &rcd = d; - ASSERT(rab.virtual_name() == '?', MSG); - ASSERT(rbc.virtual_name() == '?', MSG); - ASSERT(rcd.virtual_name() == '?', MSG); - ASSERT(rab.direct_name() == '?', MSG); - ASSERT(rbc.direct_name() == '?', MSG); - ASSERT(rcd.direct_name() == '?', MSG); + ASSERT(rab.virtual_name() == 'B', MSG); + ASSERT(rbc.virtual_name() == 'C', MSG); + ASSERT(rcd.virtual_name() == 'C', MSG); + ASSERT(rab.direct_name() == 'A', MSG); + ASSERT(rbc.direct_name() == 'B', MSG); + ASSERT(rcd.direct_name() == 'C', MSG); A &rac = c; B &rbd = d; - ASSERT(rac.virtual_name() == '?', MSG); - ASSERT(rbd.virtual_name() == '?', MSG); - ASSERT(rac.direct_name() == '?', MSG); - ASSERT(rbd.direct_name() == '?', MSG); + ASSERT(rac.virtual_name() == 'C', MSG); + ASSERT(rbd.virtual_name() == 'C', MSG); + ASSERT(rac.direct_name() == 'A', MSG); + ASSERT(rbd.direct_name() == 'B', MSG); A &rad = d; - ASSERT(rad.virtual_name() == '?', MSG); - ASSERT(rad.direct_name() == '?', MSG); + ASSERT(rad.virtual_name() == 'C', MSG); + ASSERT(rad.direct_name() == 'A', MSG); return 0; } diff --git a/exercises/19_class_virtual_destruct/main.cpp b/exercises/19_class_virtual_destruct/main.cpp index cdd54f74f..d8f387057 100644 --- a/exercises/19_class_virtual_destruct/main.cpp +++ b/exercises/19_class_virtual_destruct/main.cpp @@ -5,7 +5,8 @@ struct A { // TODO: 正确初始化静态字段 - static int num_a = 0; + + static int num_a; A() { ++num_a; @@ -20,7 +21,7 @@ struct A { }; struct B final : public A { // TODO: 正确初始化静态字段 - static int num_b = 0; + static int num_b =0; B() { ++num_b; @@ -37,10 +38,10 @@ struct B final : public A { int main(int argc, char **argv) { auto a = new A; auto b = new B; - ASSERT(A::num_a == ?, "Fill in the correct value for A::num_a"); - ASSERT(B::num_b == ?, "Fill in the correct value for B::num_b"); - ASSERT(a->name() == '?', "Fill in the correct value for a->name()"); - ASSERT(b->name() == '?', "Fill in the correct value for b->name()"); + ASSERT(A::num_a == 1, "Fill in the correct value for A::num_a"); + ASSERT(B::num_b == 1, "Fill in the correct value for B::num_b"); + ASSERT(a->name() == 'A', "Fill in the correct value for a->name()"); + ASSERT(b->name() == 'B', "Fill in the correct value for b->name()"); delete a; delete b; @@ -48,13 +49,13 @@ int main(int argc, char **argv) { ASSERT(B::num_b == 0, "Every B was destroyed"); A *ab = new B;// 派生类指针可以随意转换为基类指针 - ASSERT(A::num_a == ?, "Fill in the correct value for A::num_a"); - ASSERT(B::num_b == ?, "Fill in the correct value for B::num_b"); - ASSERT(ab->name() == '?', "Fill in the correct value for ab->name()"); + ASSERT(A::num_a == 1, "Fill in the correct value for A::num_a"); + ASSERT(B::num_b == 1, "Fill in the correct value for B::num_b"); + ASSERT(ab->name() == 'B', "Fill in the correct value for ab->name()"); // TODO: 基类指针无法随意转换为派生类指针,补全正确的转换语句 B &bb = *ab; - ASSERT(bb.name() == '?', "Fill in the correct value for bb->name()"); + ASSERT(bb.name() == 'B', "Fill in the correct value for bb->name()"); // TODO: ---- 以下代码不要修改,通过改正类定义解决编译问题 ---- delete ab;// 通过指针可以删除指向的对象,即使是多态对象 diff --git a/exercises/29_std_map/main.cpp b/exercises/29_std_map/main.cpp index fcccca347..8694881e7 100644 --- a/exercises/29_std_map/main.cpp +++ b/exercises/29_std_map/main.cpp @@ -6,11 +6,13 @@ template bool key_exists(std::map const &map, k const &key) { + return map.find(key) != map.end(); // TODO: 实现函数 } template void set(std::map &map, k key, v value) { + map[key] = value; // TODO: 实现函数 } diff --git a/exercises/31_std_shared_ptr/main.cpp b/exercises/31_std_shared_ptr/main.cpp index febbbcc6f..13372fd9c 100644 --- a/exercises/31_std_shared_ptr/main.cpp +++ b/exercises/31_std_shared_ptr/main.cpp @@ -10,36 +10,36 @@ int main(int argc, char **argv) { std::shared_ptr ptrs[]{shared, shared, shared}; std::weak_ptr observer = shared; - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 4, ""); ptrs[0].reset(); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 3, ""); ptrs[1] = nullptr; - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 2, ""); ptrs[2] = std::make_shared(*shared); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 5, ""); ptrs[0] = shared; ptrs[1] = shared; ptrs[2] = std::move(shared); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 4, ""); std::ignore = std::move(ptrs[0]); ptrs[1] = std::move(ptrs[1]); ptrs[1] = std::move(ptrs[2]); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 2, ""); shared = observer.lock(); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 3, ""); shared = nullptr; for (auto &ptr : ptrs) ptr = nullptr; - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 1, ""); shared = observer.lock(); - ASSERT(observer.use_count() == ?, ""); + ASSERT(observer.use_count() == 2, ""); return 0; } diff --git a/exercises/32_std_transform/main.cpp b/exercises/32_std_transform/main.cpp index f4dc25a5c..895fc0f36 100644 --- a/exercises/32_std_transform/main.cpp +++ b/exercises/32_std_transform/main.cpp @@ -10,6 +10,9 @@ int main(int argc, char **argv) { std::vector val{8, 13, 21, 34, 55}; // TODO: 调用 `std::transform`,将 `v` 中的每个元素乘以 2,并转换为字符串,存入 `ans` // std::vector ans + std::vector ans; + std::transform(val.begin(), val.end(), std::back_inserter(ans), + [](int x) { return std::to_string(x * 2); }); ASSERT(ans.size() == val.size(), "ans size should be equal to val size"); ASSERT(ans[0] == "16", "ans[0] should be 16"); ASSERT(ans[1] == "26", "ans[1] should be 26"); diff --git a/exercises/33_std_accumulate/main.cpp b/exercises/33_std_accumulate/main.cpp index 6326929d5..ca1ade0e4 100644 --- a/exercises/33_std_accumulate/main.cpp +++ b/exercises/33_std_accumulate/main.cpp @@ -12,6 +12,8 @@ int main(int argc, char **argv) { // - 连续存储; // 的张量占用的字节数 // int size = + int size = std::accumulate(shape, shape + 4, 1, std::multiplies()) * sizeof(DataType); + ASSERT(size == 602112, "4x1x3x224x224 = 602112"); return 0; } diff --git a/exercises/wget-log b/exercises/wget-log new file mode 100644 index 000000000..87087d6be --- /dev/null +++ b/exercises/wget-log @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-06 21:25:58-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 321K + 50K .......... .......... .......... .......... .......... 639K + 100K .......... .......... .......... .......... .......... 954K + 150K .......... .......... .......... .......... .......... 844K + 200K .......... .......... .......... .......... .......... 863K + 250K .......... .......... .......... .......... .......... 814K + 300K .......... .......... .......... .......... .......... 914K + 350K .......... .......... .......... .......... .......... 920K + 400K .......... .......... .......... .......... .......... 930K + 450K .......... .......... .......... .......... .......... 1.29M + 500K .......... .......... .......... .......... ......... 860K=0.7s + +2026-01-06 21:25:59 (760 KB/s) - ‘/dev/null’ saved [562211] + diff --git a/exercises/wget-log.1 b/exercises/wget-log.1 new file mode 100644 index 000000000..8f301b68b --- /dev/null +++ b/exercises/wget-log.1 @@ -0,0 +1,13 @@ +--2026-01-06 21:25:58-- http://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitlab.com/ [following] +--2026-01-06 21:25:58-- https://gitlab.com/ +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-06 21:25:59-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 199.59.149.231, 2a03:2880:f111:83:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|199.59.149.231|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f111:83:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/exercises/wget-log.10 b/exercises/wget-log.10 new file mode 100644 index 000000000..558eaf8cc --- /dev/null +++ b/exercises/wget-log.10 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 2.24G=0s + +2026-01-08 20:13:01 (2.24 GB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/exercises/wget-log.11 b/exercises/wget-log.11 new file mode 100644 index 000000000..484f7036b --- /dev/null +++ b/exercises/wget-log.11 @@ -0,0 +1,28 @@ +--2026-01-08 20:13:01-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-08 20:13:01-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 177K + 50K .......... .......... .......... .......... .......... 356K + 100K .......... .......... .......... .......... .......... 333K + 150K .......... .......... .......... .......... .......... 803K + 200K .......... .......... .......... .......... .......... 504K + 250K .......... .......... .......... .......... .......... 944M + 300K .......... .......... .......... .......... .......... 6.44M + 350K .......... .......... .......... .......... .......... 1.07M + 400K .......... .......... .......... .......... .......... 1.96M + 450K .......... .......... .......... .......... .......... 1.73M + 500K .......... .......... .......... .......... .......... 1.76M + 550K .......... .......... .......... .......... .......... 1.67M + 600K .......... .......... .......... .......... .......... 2.49M + 650K ....... 6.64M=0.9s + +2026-01-08 20:13:02 (715 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/exercises/wget-log.2 b/exercises/wget-log.2 new file mode 100644 index 000000000..6e62cb9e0 --- /dev/null +++ b/exercises/wget-log.2 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-06 21:25:58-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 5.41G=0s + +2026-01-06 21:25:58 (5.41 GB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/exercises/wget-log.3 b/exercises/wget-log.3 new file mode 100644 index 000000000..57edf5572 --- /dev/null +++ b/exercises/wget-log.3 @@ -0,0 +1,28 @@ +--2026-01-06 21:25:58-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13, 180.76.198.225, 180.76.198.77 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-06 21:25:58-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 774K + 50K .......... .......... .......... .......... .......... 934K + 100K .......... .......... .......... .......... .......... 925K + 150K .......... .......... .......... .......... .......... 951K + 200K .......... .......... .......... .......... .......... 845K + 250K .......... .......... .......... .......... .......... 905K + 300K .......... .......... .......... .......... .......... 944K + 350K .......... .......... .......... .......... .......... 682K + 400K .......... .......... .......... .......... .......... 611K + 450K .......... .......... .......... .......... .......... 928K + 500K .......... .......... .......... .......... .......... 992K + 550K .......... .......... .......... .......... .......... 1.94M + 600K .......... .......... .......... .......... .......... 1.83M + 650K ....... 4.93M=0.7s + +2026-01-06 21:25:59 (932 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/exercises/wget-log.4 b/exercises/wget-log.4 new file mode 100644 index 000000000..7ced06756 --- /dev/null +++ b/exercises/wget-log.4 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:42-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 268K + 50K .......... .......... .......... .......... .......... 439K + 100K .......... .......... .......... .......... .......... 419K + 150K .......... .......... .......... .......... .......... 434K + 200K .......... .......... .......... .......... .......... 434K + 250K .......... .......... .......... .......... .......... 437K + 300K .......... .......... .......... .......... .......... 472K + 350K .......... .......... .......... .......... .......... 549K + 400K .......... .......... .......... .......... .......... 645K + 450K .......... .......... .......... .......... .......... 896K + 500K .......... .......... .......... .......... ......... 951K=1.1s + +2026-01-07 21:36:43 (479 KB/s) - ‘/dev/null’ saved [562422] + diff --git a/exercises/wget-log.5 b/exercises/wget-log.5 new file mode 100644 index 000000000..b38dd8e81 --- /dev/null +++ b/exercises/wget-log.5 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:42-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-07 21:36:42-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 103.228.130.27, 2a03:2880:f12c:183:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|103.228.130.27|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f12c:183:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/exercises/wget-log.6 b/exercises/wget-log.6 new file mode 100644 index 000000000..8ab7a5486 --- /dev/null +++ b/exercises/wget-log.6 @@ -0,0 +1,28 @@ +--2026-01-07 21:36:42-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.198.225, 180.76.198.77, 180.76.199.13 +Connecting to gitee.com (gitee.com)|180.76.198.225|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-07 21:36:42-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.198.225|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 464K + 50K .......... .......... .......... .......... .......... 464K + 100K .......... .......... .......... .......... .......... 461K + 150K .......... .......... .......... .......... .......... 448K + 200K .......... .......... .......... .......... .......... 450K + 250K .......... .......... .......... .......... .......... 471K + 300K .......... .......... .......... .......... .......... 526K + 350K .......... .......... .......... .......... .......... 471K + 400K .......... .......... .......... .......... .......... 750K + 450K .......... .......... .......... .......... .......... 902K + 500K .......... .......... .......... .......... .......... 1020K + 550K .......... .......... .......... .......... .......... 1.08M + 600K .......... .......... .......... .......... .......... 1.73M + 650K ....... 259M=1.1s + +2026-01-07 21:36:43 (598 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/exercises/wget-log.7 b/exercises/wget-log.7 new file mode 100644 index 000000000..c191f5cca --- /dev/null +++ b/exercises/wget-log.7 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:42-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 2.53G=0s + +2026-01-07 21:36:42 (2.53 GB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/exercises/wget-log.8 b/exercises/wget-log.8 new file mode 100644 index 000000000..25f6d5f06 --- /dev/null +++ b/exercises/wget-log.8 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 280K + 50K .......... .......... .......... .......... .......... 590K + 100K .......... .......... .......... .......... .......... 561K + 150K .......... .......... .......... .......... .......... 598K + 200K .......... .......... .......... .......... .......... 561K + 250K .......... .......... .......... .......... .......... 605K + 300K .......... .......... .......... .......... .......... 860K + 350K .......... .......... .......... .......... .......... 676K + 400K .......... .......... .......... .......... .......... 1020K + 450K .......... .......... .......... .......... .......... 895K + 500K .......... .......... .......... .......... ......... 1.03M=0.9s + +2026-01-08 20:13:02 (616 KB/s) - ‘/dev/null’ saved [562396] + diff --git a/exercises/wget-log.9 b/exercises/wget-log.9 new file mode 100644 index 000000000..f8acf4ff4 --- /dev/null +++ b/exercises/wget-log.9 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-08 20:13:01-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 23.225.141.210, 2a03:2880:f10d:183:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|23.225.141.210|:443... connected. +Unable to establish SSL connection. diff --git a/wget-log b/wget-log new file mode 100644 index 000000000..ebb7cb939 --- /dev/null +++ b/wget-log @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-06 21:25:56-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 292K + 50K .......... .......... .......... .......... .......... 625K + 100K .......... .......... .......... .......... .......... 1.32M + 150K .......... .......... .......... .......... .......... 1.09M + 200K .......... .......... .......... .......... .......... 1.16M + 250K .......... .......... .......... .......... .......... 1.20M + 300K .......... .......... .......... .......... .......... 1.11M + 350K .......... .......... .......... .......... .......... 1.05M + 400K .......... .......... .......... .......... .......... 849K + 450K .......... .......... .......... .......... .......... 845K + 500K .......... .......... .......... .......... ......... 865K=0.7s + +2026-01-06 21:25:57 (806 KB/s) - ‘/dev/null’ saved [562217] + diff --git a/wget-log.1 b/wget-log.1 new file mode 100644 index 000000000..4f420009e --- /dev/null +++ b/wget-log.1 @@ -0,0 +1,13 @@ +--2026-01-06 21:25:56-- http://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitlab.com/ [following] +--2026-01-06 21:25:57-- https://gitlab.com/ +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-06 21:25:58-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 199.59.149.231, 2a03:2880:f111:83:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|199.59.149.231|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f111:83:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/wget-log.10 b/wget-log.10 new file mode 100644 index 000000000..32752f0fe --- /dev/null +++ b/wget-log.10 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 1.14G=0s + +2026-01-08 20:13:00 (1.14 GB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/wget-log.11 b/wget-log.11 new file mode 100644 index 000000000..2042ebe51 --- /dev/null +++ b/wget-log.11 @@ -0,0 +1,28 @@ +--2026-01-08 20:13:00-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-08 20:13:00-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 723K + 50K .......... .......... .......... .......... .......... 613K + 100K .......... .......... .......... .......... .......... 780K + 150K .......... .......... .......... .......... .......... 721K + 200K .......... .......... .......... .......... .......... 738K + 250K .......... .......... .......... .......... .......... 525K + 300K .......... .......... .......... .......... .......... 395K + 350K .......... .......... .......... .......... .......... 288K + 400K .......... .......... .......... .......... .......... 594K + 450K .......... .......... .......... .......... .......... 674K + 500K .......... .......... .......... .......... .......... 578K + 550K .......... .......... .......... .......... .......... 633K + 600K .......... .......... .......... .......... .......... 1.32M + 650K ....... 18.4M=1.1s + +2026-01-08 20:13:02 (593 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/wget-log.2 b/wget-log.2 new file mode 100644 index 000000000..65e9f3270 --- /dev/null +++ b/wget-log.2 @@ -0,0 +1,28 @@ +--2026-01-06 21:25:56-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13, 180.76.198.77, 180.76.198.225 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-06 21:25:57-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 527K + 50K .......... .......... .......... .......... .......... 577K + 100K .......... .......... .......... .......... .......... 504K + 150K .......... .......... .......... .......... .......... 801K + 200K .......... .......... .......... .......... .......... 901K + 250K .......... .......... .......... .......... .......... 895K + 300K .......... .......... .......... .......... .......... 932K + 350K .......... .......... .......... .......... .......... 939K + 400K .......... .......... .......... .......... .......... 1.42M + 450K .......... .......... .......... .......... .......... 1.61M + 500K .......... .......... .......... .......... .......... 2.16M + 550K .......... .......... .......... .......... .......... 1.66M + 600K .......... .......... .......... .......... .......... 1.48M + 650K ....... 357M=0.7s + +2026-01-06 21:25:58 (923 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/wget-log.3 b/wget-log.3 new file mode 100644 index 000000000..2b294407b --- /dev/null +++ b/wget-log.3 @@ -0,0 +1,15 @@ +--2026-01-06 21:25:56-- http://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:80... connected. +HTTP request sent, awaiting response... 302 Moved Temporarily +Location: https://gitcode.com/ [following] +--2026-01-06 21:25:57-- https://gitcode.com/ +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 2.18G=0s + +2026-01-06 21:25:57 (2.18 GB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/wget-log.4 b/wget-log.4 new file mode 100644 index 000000000..ff8dc2927 --- /dev/null +++ b/wget-log.4 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:41-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 316K + 50K .......... .......... .......... .......... .......... 623K + 100K .......... .......... .......... .......... .......... 350K + 150K .......... .......... .......... .......... .......... 28.2M + 200K .......... .......... .......... .......... .......... 553K + 250K .......... .......... .......... .......... .......... 464K + 300K .......... .......... .......... .......... .......... 389K + 350K .......... .......... .......... .......... .......... 443K + 400K .......... .......... .......... .......... .......... 413K + 450K .......... .......... .......... .......... .......... 442K + 500K .......... .......... .......... .......... ......... 423K=1.2s + +2026-01-07 21:36:43 (468 KB/s) - ‘/dev/null’ saved [562417] + diff --git a/wget-log.5 b/wget-log.5 new file mode 100644 index 000000000..4d8ce2e26 --- /dev/null +++ b/wget-log.5 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:41-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3651 (3.6K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 774M=0s + +2026-01-07 21:36:42 (774 MB/s) - ‘/dev/null’ saved [3651/3651] + diff --git a/wget-log.6 b/wget-log.6 new file mode 100644 index 000000000..f23d8ea4e --- /dev/null +++ b/wget-log.6 @@ -0,0 +1,28 @@ +--2026-01-07 21:36:41-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.198.225, 180.76.199.13, 180.76.198.77 +Connecting to gitee.com (gitee.com)|180.76.198.225|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-07 21:36:41-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.198.225|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 687K + 50K .......... .......... .......... .......... .......... 866K + 100K .......... .......... .......... .......... .......... 909K + 150K .......... .......... .......... .......... .......... 1.22M + 200K .......... .......... .......... .......... .......... 667K + 250K .......... .......... .......... .......... .......... 471K + 300K .......... .......... .......... .......... .......... 436K + 350K .......... .......... .......... .......... .......... 349K + 400K .......... .......... .......... .......... .......... 453K + 450K .......... .......... .......... .......... .......... 445K + 500K .......... .......... .......... .......... .......... 506K + 550K .......... .......... .......... .......... .......... 607K + 600K .......... .......... .......... .......... .......... 628K + 650K ....... 1.50M=1.2s + +2026-01-07 21:36:43 (570 KB/s) - ‘/dev/null’ saved [672773] + diff --git a/wget-log.7 b/wget-log.7 new file mode 100644 index 000000000..ebfdb088c --- /dev/null +++ b/wget-log.7 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-07 21:36:41-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-07 21:36:42-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 103.228.130.27, 2a03:2880:f12c:183:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|103.228.130.27|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f12c:183:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/wget-log.8 b/wget-log.8 new file mode 100644 index 000000000..1ef0700c9 --- /dev/null +++ b/wget-log.8 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 387K + 50K .......... .......... .......... .......... .......... 680K + 100K .......... .......... .......... .......... .......... 1.08M + 150K .......... .......... .......... .......... .......... 791K + 200K .......... .......... .......... .......... .......... 855K + 250K .......... .......... .......... .......... .......... 660K + 300K .......... .......... .......... .......... .......... 604K + 350K .......... .......... .......... .......... .......... 591K + 400K .......... .......... .......... .......... .......... 590K + 450K .......... .......... .......... .......... .......... 468K + 500K .......... .......... .......... .......... ......... 684K=0.9s + +2026-01-08 20:13:01 (627 KB/s) - ‘/dev/null’ saved [562397] + diff --git a/wget-log.9 b/wget-log.9 new file mode 100644 index 000000000..f8acf4ff4 --- /dev/null +++ b/wget-log.9 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-08 20:13:00-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-08 20:13:01-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 23.225.141.210, 2a03:2880:f10d:183:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|23.225.141.210|:443... connected. +Unable to establish SSL connection. From c6103c9b34c29dcdbafdf8e8d5ca5d0da0668e2e Mon Sep 17 00:00:00 2001 From: "yinghui.cai" Date: Fri, 9 Jan 2026 17:29:54 +0800 Subject: [PATCH 2/2] commmit exercises --- exercises/19_class_virtual_destruct/main.cpp | 11 ++-- exercises/20_function_template/main.cpp | 5 +- exercises/21_runtime_datatype/main.cpp | 8 ++- exercises/22_class_template/main.cpp | 27 ++++++++ exercises/23_template_const/main.cpp | 9 +++ exercises/24_std_array/main.cpp | 16 ++--- exercises/25_std_vector/main.cpp | 66 ++++++++++---------- exercises/26_std_vector_bool/main.cpp | 16 ++--- exercises/27_strides/main.cpp | 5 ++ exercises/28_std_string/main.cpp | 6 +- exercises/30_std_unique_ptr/main.cpp | 6 +- exercises/31_std_shared_ptr/main.cpp | 8 +-- exercises/wget-log.12 | 22 +++++++ exercises/wget-log.13 | 28 +++++++++ exercises/wget-log.14 | 10 +++ exercises/wget-log.15 | 12 ++++ wget-log.12 | 22 +++++++ wget-log.13 | 10 +++ wget-log.14 | 12 ++++ wget-log.15 | 28 +++++++++ 20 files changed, 262 insertions(+), 65 deletions(-) create mode 100644 exercises/wget-log.12 create mode 100644 exercises/wget-log.13 create mode 100644 exercises/wget-log.14 create mode 100644 exercises/wget-log.15 create mode 100644 wget-log.12 create mode 100644 wget-log.13 create mode 100644 wget-log.14 create mode 100644 wget-log.15 diff --git a/exercises/19_class_virtual_destruct/main.cpp b/exercises/19_class_virtual_destruct/main.cpp index d8f387057..f2e0a5fa4 100644 --- a/exercises/19_class_virtual_destruct/main.cpp +++ b/exercises/19_class_virtual_destruct/main.cpp @@ -11,7 +11,7 @@ struct A { A() { ++num_a; } - ~A() { + virtual ~A() { --num_a; } @@ -21,7 +21,7 @@ struct A { }; struct B final : public A { // TODO: 正确初始化静态字段 - static int num_b =0; + static int num_b; B() { ++num_b; @@ -35,10 +35,13 @@ struct B final : public A { } }; +int A::num_a = 0; +int B::num_b = 0; + int main(int argc, char **argv) { auto a = new A; auto b = new B; - ASSERT(A::num_a == 1, "Fill in the correct value for A::num_a"); + ASSERT(A::num_a == 2, "Fill in the correct value for A::num_a"); ASSERT(B::num_b == 1, "Fill in the correct value for B::num_b"); ASSERT(a->name() == 'A', "Fill in the correct value for a->name()"); ASSERT(b->name() == 'B', "Fill in the correct value for b->name()"); @@ -54,7 +57,7 @@ int main(int argc, char **argv) { ASSERT(ab->name() == 'B', "Fill in the correct value for ab->name()"); // TODO: 基类指针无法随意转换为派生类指针,补全正确的转换语句 - B &bb = *ab; + B &bb = *static_cast(ab); ASSERT(bb.name() == 'B', "Fill in the correct value for bb->name()"); // TODO: ---- 以下代码不要修改,通过改正类定义解决编译问题 ---- diff --git a/exercises/20_function_template/main.cpp b/exercises/20_function_template/main.cpp index cb6d978d3..07421a84a 100644 --- a/exercises/20_function_template/main.cpp +++ b/exercises/20_function_template/main.cpp @@ -2,7 +2,8 @@ // READ: 函数模板 // TODO: 将这个函数模板化 -int plus(int a, int b) { +template +T plus(T a, T b) { return a + b; } @@ -14,7 +15,7 @@ int main(int argc, char **argv) { ASSERT(plus(1.25f, 2.5f) == 3.75f, "Plus two float"); ASSERT(plus(1.25, 2.5) == 3.75, "Plus two double"); // TODO: 修改判断条件使测试通过 - ASSERT(plus(0.1, 0.2) == 0.3, "How to make this pass?"); + ASSERT(plus(0.1f, 0.2f) == 0.3f, "How to make this pass?"); return 0; } diff --git a/exercises/21_runtime_datatype/main.cpp b/exercises/21_runtime_datatype/main.cpp index 9c4bf376a..f0de927f6 100644 --- a/exercises/21_runtime_datatype/main.cpp +++ b/exercises/21_runtime_datatype/main.cpp @@ -18,13 +18,19 @@ struct TaggedUnion { }; // TODO: 将这个函数模板化用于 sigmoid_dyn -float sigmoid(float x) { +template +T sigmoid(T x) { return 1 / (1 + std::exp(-x)); } TaggedUnion sigmoid_dyn(TaggedUnion x) { TaggedUnion ans{x.type}; // TODO: 根据 type 调用 sigmoid + if (x.type == DataType::Float) { + ans.f = sigmoid(x.f); + } else if (x.type == DataType::Double) { + ans.d = sigmoid(x.d); + } return ans; } diff --git a/exercises/22_class_template/main.cpp b/exercises/22_class_template/main.cpp index d4985d904..ab822236e 100644 --- a/exercises/22_class_template/main.cpp +++ b/exercises/22_class_template/main.cpp @@ -10,6 +10,10 @@ struct Tensor4D { Tensor4D(unsigned int const shape_[4], T const *data_) { unsigned int size = 1; // TODO: 填入正确的 shape 并计算 size + for (int i = 0; i < 4; ++i) { + shape[i] = shape_[i]; + size *= shape[i]; + } data = new T[size]; std::memcpy(data, data_, size * sizeof(T)); } @@ -28,6 +32,29 @@ struct Tensor4D { // 则 `this` 与 `others` 相加时,3 个形状为 `[1, 2, 1, 4]` 的子张量各自与 `others` 对应项相加。 Tensor4D &operator+=(Tensor4D const &others) { // TODO: 实现单向广播的加法 + unsigned int this_stride[4]; + unsigned int others_stride[4]; + this_stride[3] = 1; + others_stride[3] = 1; + for (int i = 2; i >= 0; --i) { + this_stride[i] = this_stride[i + 1] * shape[i + 1]; + others_stride[i] = others_stride[i + 1] * others.shape[i + 1]; + } + for (unsigned int n = 0; n < shape[0]; ++n) { + for (unsigned int c = 0; c < shape[1]; ++c) { + for (unsigned int h = 0; h < shape[2]; ++h) { + for (unsigned int w = 0; w < shape[3]; ++w) { + unsigned int this_index = n * this_stride[0] + c * this_stride[1] + h * this_stride[2] + w * this_stride[3]; + unsigned int others_index = (others.shape[0] == 1 ? 0 : n * others_stride[0]) + + (others.shape[1] == 1 ? 0 : c * others_stride[1]) + + (others.shape[2] == 1 ? 0 : h * others_stride[2]) + + (others.shape[3] == 1 ? 0 : w * others_stride[3]); + data[this_index] += others.data[others_index]; + } + } + } + } + return *this; } }; diff --git a/exercises/23_template_const/main.cpp b/exercises/23_template_const/main.cpp index e0105e168..2200d071f 100644 --- a/exercises/23_template_const/main.cpp +++ b/exercises/23_template_const/main.cpp @@ -11,6 +11,10 @@ struct Tensor { Tensor(unsigned int const shape_[N]) { unsigned int size = 1; // TODO: 填入正确的 shape 并计算 size + for (unsigned int i = 0; i < N; ++i) { + shape[i] = shape_[i]; + size *= shape[i]; + } data = new T[size]; std::memset(data, 0, size * sizeof(T)); } @@ -35,6 +39,11 @@ struct Tensor { for (unsigned int i = 0; i < N; ++i) { ASSERT(indices[i] < shape[i], "Invalid index"); // TODO: 计算 index + unsigned int stride = 1; + for (unsigned int j = i + 1; j < N; ++j) { + stride *= shape[j]; + } + index += indices[i] * stride; } return index; } diff --git a/exercises/24_std_array/main.cpp b/exercises/24_std_array/main.cpp index c29718d9d..1130c998f 100644 --- a/exercises/24_std_array/main.cpp +++ b/exercises/24_std_array/main.cpp @@ -8,21 +8,21 @@ int main(int argc, char **argv) { { std::array arr{{1, 2, 3, 4, 5}}; - ASSERT(arr.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(arr) == ?, "Fill in the correct value."); + ASSERT(arr.size() == 5, "Fill in the correct value."); + ASSERT(sizeof(arr) == 20, "Fill in the correct value."); int ans[]{1, 2, 3, 4, 5}; - ASSERT(std::memcmp(arr.?, ans, ?) == 0, "Fill in the correct values."); + ASSERT(std::memcmp(arr.data(), ans, sizeof(ans)) == 0, "Fill in the correct values."); } { std::array arr; - ASSERT(arr.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(arr) == ?, "Fill in the correct value."); + ASSERT(arr.size() == 8, "Fill in the correct value."); + ASSERT(sizeof(arr) == 64, "Fill in the correct value."); } { std::array arr{"Hello, InfiniTensor!"}; - ASSERT(arr.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(arr) == ?, "Fill in the correct value."); - ASSERT(std::strcmp(arr.?, "Hello, InfiniTensor!") == 0, "Fill in the correct value."); + ASSERT(arr.size() == 21, "Fill in the correct value."); + ASSERT(sizeof(arr) == 21, "Fill in the correct value."); + ASSERT(std::strcmp(arr.data(), "Hello, InfiniTensor!") == 0, "Fill in the correct value."); } return 0; } diff --git a/exercises/25_std_vector/main.cpp b/exercises/25_std_vector/main.cpp index f9e41bb78..805635c37 100644 --- a/exercises/25_std_vector/main.cpp +++ b/exercises/25_std_vector/main.cpp @@ -8,81 +8,81 @@ int main(int argc, char **argv) { { std::vector vec{1, 2, 3, 4, 5}; - ASSERT(vec.size() == ?, "Fill in the correct value."); + ASSERT(vec.size() == 5, "Fill in the correct value."); // THINK: `std::vector` 的大小是什么意思?与什么有关? - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(sizeof(vec) == 24, "Fill in the correct value."); int ans[]{1, 2, 3, 4, 5}; - ASSERT(std::memcmp(vec.?, ans, sizeof(ans)) == 0, "Fill in the correct values."); + ASSERT(std::memcmp(vec.data(), ans, sizeof(ans)) == 0, "Fill in the correct values."); } { std::vector vec{1, 2, 3, 4, 5}; { - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(vec.size() == 5, "Fill in the correct value."); + ASSERT(sizeof(vec) == 24, "Fill in the correct value."); double ans[]{1, 2, 3, 4, 5}; - ASSERT(std::memcmp(vec.?, ans, sizeof(ans)) == 0, "Fill in the correct values."); + ASSERT(std::memcmp(vec.data(), ans, sizeof(ans)) == 0, "Fill in the correct values."); } { vec.push_back(6); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(vec.size() == 6, "Fill in the correct value."); + ASSERT(sizeof(vec) == 24, "Fill in the correct value."); vec.pop_back(); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(vec.size() == 5, "Fill in the correct value."); + ASSERT(sizeof(vec) == 24, "Fill in the correct value."); } { vec[4] = 6; - ASSERT(vec[0] == ?, "Fill in the correct value."); - ASSERT(vec[1] == ?, "Fill in the correct value."); - ASSERT(vec[2] == ?, "Fill in the correct value."); - ASSERT(vec[3] == ?, "Fill in the correct value."); - ASSERT(vec[4] == ?, "Fill in the correct value."); + ASSERT(vec[0] == 1, "Fill in the correct value."); + ASSERT(vec[1] == 2, "Fill in the correct value."); + ASSERT(vec[2] == 3, "Fill in the correct value."); + ASSERT(vec[3] == 4, "Fill in the correct value."); + ASSERT(vec[4] == 6, "Fill in the correct value."); } { // THINK: `std::vector` 插入删除的时间复杂度是什么? - vec.insert(?, 1.5); + vec.insert(vec.begin() + 1, 1.5); ASSERT((vec == std::vector{1, 1.5, 2, 3, 4, 6}), "Make this assertion pass."); - vec.erase(?); + vec.erase(vec.begin() + 3); ASSERT((vec == std::vector{1, 1.5, 2, 4, 6}), "Make this assertion pass."); } { vec.shrink_to_fit(); - ASSERT(vec.capacity() == ?, "Fill in the correct value."); + ASSERT(vec.capacity() == 5, "Fill in the correct value."); vec.clear(); ASSERT(vec.empty(), "`vec` is empty now."); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(vec.capacity() == ?, "Fill in the correct value."); + ASSERT(vec.size() == 0, "Fill in the correct value."); + ASSERT(vec.capacity() == 5, "Fill in the correct value."); } } { - std::vector vec(?, ?); // TODO: 调用正确的构造函数 + std::vector vec(48, 'z'); // TODO: 调用正确的构造函数 ASSERT(vec[0] == 'z', "Make this assertion pass."); ASSERT(vec[47] == 'z', "Make this assertion pass."); ASSERT(vec.size() == 48, "Make this assertion pass."); - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(sizeof(vec) == 24, "Fill in the correct value."); { auto capacity = vec.capacity(); vec.resize(16); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(vec.capacity() == ?, "Fill in a correct identifier."); + ASSERT(vec.size() == 16, "Fill in the correct value."); + ASSERT(vec.capacity() == capacity, "Fill in a correct identifier."); } { vec.reserve(256); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(vec.capacity() == ?, "Fill in the correct value."); + ASSERT(vec.size() == 16, "Fill in the correct value."); + ASSERT(vec.capacity() == 256, "Fill in the correct value."); } { vec.push_back('a'); vec.push_back('b'); vec.push_back('c'); vec.push_back('d'); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(vec.capacity() == ?, "Fill in the correct value."); - ASSERT(vec[15] == ?, "Fill in the correct value."); - ASSERT(vec[?] == 'a', "Fill in the correct value."); - ASSERT(vec[?] == 'b', "Fill in the correct value."); - ASSERT(vec[?] == 'c', "Fill in the correct value."); - ASSERT(vec[?] == 'd', "Fill in the correct value."); + ASSERT(vec.size() == 20, "Fill in the correct value."); + ASSERT(vec.capacity() == 256, "Fill in the correct value."); + ASSERT(vec[15] == 'z', "Fill in the correct value."); + ASSERT(vec[16] == 'a', "Fill in the correct value."); + ASSERT(vec[17] == 'b', "Fill in the correct value."); + ASSERT(vec[18] == 'c', "Fill in the correct value."); + ASSERT(vec[19] == 'd', "Fill in the correct value."); } } diff --git a/exercises/26_std_vector_bool/main.cpp b/exercises/26_std_vector_bool/main.cpp index b4ab4f9c4..15103c20e 100644 --- a/exercises/26_std_vector_bool/main.cpp +++ b/exercises/26_std_vector_bool/main.cpp @@ -6,29 +6,29 @@ // TODO: 将下列 `?` 替换为正确的代码 int main(int argc, char **argv) { - std::vector vec(?, ?);// TODO: 正确调用构造函数 + std::vector vec(100, true);// TODO: 正确调用构造函数 ASSERT(vec[0], "Make this assertion pass."); ASSERT(vec[99], "Make this assertion pass."); ASSERT(vec.size() == 100, "Make this assertion pass."); // NOTICE: 平台相关!注意 CI:Ubuntu 上的值。 std::cout << "sizeof(std::vector) = " << sizeof(std::vector) << std::endl; - ASSERT(sizeof(vec) == ?, "Fill in the correct value."); + ASSERT(sizeof(vec) == 40, "Fill in the correct value."); { vec[20] = false; - ASSERT(?vec[20], "Fill in `vec[20]` or `!vec[20]`."); + ASSERT(!vec[20], "Fill in `vec[20]` or `!vec[20]`."); } { vec.push_back(false); - ASSERT(vec.size() == ?, "Fill in the correct value."); - ASSERT(?vec[100], "Fill in `vec[100]` or `!vec[100]`."); + ASSERT(vec.size() == 101, "Fill in the correct value."); + ASSERT(!vec[100], "Fill in `vec[100]` or `!vec[100]`."); } { auto ref = vec[30]; - ASSERT(?ref, "Fill in `ref` or `!ref`"); + ASSERT(ref, "Fill in `ref` or `!ref`"); ref = false; - ASSERT(?ref, "Fill in `ref` or `!ref`"); + ASSERT(!ref, "Fill in `ref` or `!ref`"); // THINK: WHAT and WHY? - ASSERT(?vec[30], "Fill in `vec[30]` or `!vec[30]`."); + ASSERT(!vec[30], "Fill in `vec[30]` or `!vec[30]`."); } return 0; } diff --git a/exercises/27_strides/main.cpp b/exercises/27_strides/main.cpp index baceaf2a9..4c8b5fcaf 100644 --- a/exercises/27_strides/main.cpp +++ b/exercises/27_strides/main.cpp @@ -18,6 +18,11 @@ std::vector strides(std::vector const &shape) { // TODO: 完成函数体,根据张量形状计算张量连续存储时的步长。 // READ: 逆向迭代器 std::vector::rbegin // 使用逆向迭代器可能可以简化代码 + udim stride = 1; + for (int i = shape.size() - 1; i >= 0; --i) { + strides[i] = stride; + stride *= shape[i]; + } return strides; } diff --git a/exercises/28_std_string/main.cpp b/exercises/28_std_string/main.cpp index d8b276274..5ca96a9ee 100644 --- a/exercises/28_std_string/main.cpp +++ b/exercises/28_std_string/main.cpp @@ -10,9 +10,9 @@ int main(int argc, char **argv) { auto world = "world"; // READ: `decltype` 表达式 // READ: `std::is_same_v` 元编程判别 - ASSERT((std::is_same_v), "Fill in the missing type."); - ASSERT((std::is_same_v), "Fill in the missing type."); + ASSERT((std::is_same_v), "Fill in the missing type."); + ASSERT((std::is_same_v), "Fill in the missing type."); // TODO: 将 `?` 替换为正确的字符串 - ASSERT(hello + ", " + world + '!' == "?", "Fill in the missing string."); + ASSERT(hello + ", " + world + '!' == "Hello, world!", "Fill in the missing string."); return 0; } diff --git a/exercises/30_std_unique_ptr/main.cpp b/exercises/30_std_unique_ptr/main.cpp index 9b98b5794..79d03c73d 100644 --- a/exercises/30_std_unique_ptr/main.cpp +++ b/exercises/30_std_unique_ptr/main.cpp @@ -53,8 +53,10 @@ int main(int argc, char **argv) { {"fd"}, // TODO: 分析 problems[1] 中资源的生命周期,将记录填入 `std::vector` // NOTICE: 此题结果依赖对象析构逻辑,平台相关,提交时以 CI 实际运行平台为准 - {"", "", "", "", "", "", "", ""}, - {"", "", "", "", "", "", "", ""}, + // Analysis for problems[1] + {"d", "ffr"}, + // Analysis for problems[2] + {"d", "d", "r"}, }; // ---- 不要修改以下代码 ---- diff --git a/exercises/31_std_shared_ptr/main.cpp b/exercises/31_std_shared_ptr/main.cpp index 13372fd9c..d35134457 100644 --- a/exercises/31_std_shared_ptr/main.cpp +++ b/exercises/31_std_shared_ptr/main.cpp @@ -19,12 +19,12 @@ int main(int argc, char **argv) { ASSERT(observer.use_count() == 2, ""); ptrs[2] = std::make_shared(*shared); - ASSERT(observer.use_count() == 5, ""); + ASSERT(observer.use_count() == 1, ""); ptrs[0] = shared; ptrs[1] = shared; ptrs[2] = std::move(shared); - ASSERT(observer.use_count() == 4, ""); + ASSERT(observer.use_count() == 3, ""); std::ignore = std::move(ptrs[0]); ptrs[1] = std::move(ptrs[1]); @@ -36,10 +36,10 @@ int main(int argc, char **argv) { shared = nullptr; for (auto &ptr : ptrs) ptr = nullptr; - ASSERT(observer.use_count() == 1, ""); + ASSERT(observer.use_count() == 0, ""); shared = observer.lock(); - ASSERT(observer.use_count() == 2, ""); + ASSERT(observer.use_count() == 0, ""); return 0; } diff --git a/exercises/wget-log.12 b/exercises/wget-log.12 new file mode 100644 index 000000000..39684fba4 --- /dev/null +++ b/exercises/wget-log.12 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:34-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 259K + 50K .......... .......... .......... .......... .......... 432K + 100K .......... .......... .......... .......... .......... 410K + 150K .......... .......... .......... .......... .......... 462K + 200K .......... .......... .......... .......... .......... 428K + 250K .......... .......... .......... .......... .......... 432K + 300K .......... .......... .......... .......... .......... 499K + 350K .......... .......... .......... .......... .......... 571K + 400K .......... .......... .......... .......... .......... 634K + 450K .......... .......... .......... .......... .......... 833K + 500K .......... .......... .......... .......... ......... 893K=1.2s + +2026-01-09 16:49:35 (476 KB/s) - ‘/dev/null’ saved [562412] + diff --git a/exercises/wget-log.13 b/exercises/wget-log.13 new file mode 100644 index 000000000..6812e7e1b --- /dev/null +++ b/exercises/wget-log.13 @@ -0,0 +1,28 @@ +--2026-01-09 16:49:34-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-09 16:49:34-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 480K + 50K .......... .......... .......... .......... .......... 449K + 100K .......... .......... .......... .......... .......... 434K + 150K .......... .......... .......... .......... .......... 485K + 200K .......... .......... .......... .......... .......... 447K + 250K .......... .......... .......... .......... .......... 546K + 300K .......... .......... .......... .......... .......... 611K + 350K .......... .......... .......... .......... .......... 450K + 400K .......... .......... .......... .......... .......... 922K + 450K .......... .......... .......... .......... .......... 919K + 500K .......... .......... .......... .......... .......... 1.62M + 550K .......... .......... .......... .......... .......... 1.76M + 600K .......... .......... .......... .......... .......... 1.79M + 650K ....... 3.39M=1.0s + +2026-01-09 16:49:35 (640 KB/s) - ‘/dev/null’ saved [672997] + diff --git a/exercises/wget-log.14 b/exercises/wget-log.14 new file mode 100644 index 000000000..b70a3c981 --- /dev/null +++ b/exercises/wget-log.14 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:34-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-09 16:49:34-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 202.160.128.238, 2a03:2880:f129:83:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|202.160.128.238|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f129:83:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/exercises/wget-log.15 b/exercises/wget-log.15 new file mode 100644 index 000000000..854834a0a --- /dev/null +++ b/exercises/wget-log.15 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:34-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3538 (3.5K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 5.08G=0s + +2026-01-09 16:49:34 (5.08 GB/s) - ‘/dev/null’ saved [3538/3538] + diff --git a/wget-log.12 b/wget-log.12 new file mode 100644 index 000000000..7d2954765 --- /dev/null +++ b/wget-log.12 @@ -0,0 +1,22 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:33-- https://github.com/ +Resolving github.com (github.com)... 20.205.243.166 +Connecting to github.com (github.com)|20.205.243.166|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 310K + 50K .......... .......... .......... .......... .......... 626K + 100K .......... .......... .......... .......... .......... 845K + 150K .......... .......... .......... .......... .......... 1.06M + 200K .......... .......... .......... .......... .......... 700K + 250K .......... .......... .......... .......... .......... 568K + 300K .......... .......... .......... .......... .......... 409K + 350K .......... .......... .......... .......... .......... 449K + 400K .......... .......... .......... .......... .......... 418K + 450K .......... .......... .......... .......... .......... 433K + 500K .......... .......... .......... .......... ......... 438K=1.1s + +2026-01-09 16:49:35 (505 KB/s) - ‘/dev/null’ saved [562416] + diff --git a/wget-log.13 b/wget-log.13 new file mode 100644 index 000000000..8e4e544d3 --- /dev/null +++ b/wget-log.13 @@ -0,0 +1,10 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:33-- https://gitlab.com/ +Resolving gitlab.com (gitlab.com)... 172.65.251.78, 2606:4700:90:0:f22e:fbec:5bed:a9b9 +Connecting to gitlab.com (gitlab.com)|172.65.251.78|:443... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://about.gitlab.com/ [following] +--2026-01-09 16:49:34-- https://about.gitlab.com/ +Resolving about.gitlab.com (about.gitlab.com)... 202.160.128.238, 2a03:2880:f129:83:face:b00c:0:25de +Connecting to about.gitlab.com (about.gitlab.com)|202.160.128.238|:443... failed: Connection timed out. +Connecting to about.gitlab.com (about.gitlab.com)|2a03:2880:f129:83:face:b00c:0:25de|:443... failed: Connection refused. diff --git a/wget-log.14 b/wget-log.14 new file mode 100644 index 000000000..53ec68048 --- /dev/null +++ b/wget-log.14 @@ -0,0 +1,12 @@ +URL transformed to HTTPS due to an HSTS policy +--2026-01-09 16:49:33-- https://gitcode.com/ +Resolving gitcode.com (gitcode.com)... 116.205.2.91 +Connecting to gitcode.com (gitcode.com)|116.205.2.91|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 3538 (3.5K) [text/html] +Saving to: ‘/dev/null’ + + 0K ... 100% 1.91G=0s + +2026-01-09 16:49:33 (1.91 GB/s) - ‘/dev/null’ saved [3538/3538] + diff --git a/wget-log.15 b/wget-log.15 new file mode 100644 index 000000000..2123d326d --- /dev/null +++ b/wget-log.15 @@ -0,0 +1,28 @@ +--2026-01-09 16:49:33-- http://gitee.com/ +Resolving gitee.com (gitee.com)... 180.76.199.13 +Connecting to gitee.com (gitee.com)|180.76.199.13|:80... connected. +HTTP request sent, awaiting response... 301 Moved Permanently +Location: https://gitee.com/ [following] +--2026-01-09 16:49:33-- https://gitee.com/ +Connecting to gitee.com (gitee.com)|180.76.199.13|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [text/html] +Saving to: ‘/dev/null’ + + 0K .......... .......... .......... .......... .......... 698K + 50K .......... .......... .......... .......... .......... 713K + 100K .......... .......... .......... .......... .......... 693K + 150K .......... .......... .......... .......... .......... 729K + 200K .......... .......... .......... .......... .......... 660K + 250K .......... .......... .......... .......... .......... 447K + 300K .......... .......... .......... .......... .......... 441K + 350K .......... .......... .......... .......... .......... 353K + 400K .......... .......... .......... .......... .......... 445K + 450K .......... .......... .......... .......... .......... 468K + 500K .......... .......... .......... .......... .......... 566K + 550K .......... .......... .......... .......... .......... 569K + 600K .......... .......... .......... .......... .......... 642K + 650K ....... 3.37M=1.2s + +2026-01-09 16:49:35 (548 KB/s) - ‘/dev/null’ saved [672997] +