-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
6 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
#include "../exercise.h" | ||
#include <map> | ||
#include <unordered_map> | ||
|
||
// READ: `std::map` <https://zh.cppreference.com/w/cpp/container/map> | ||
// READ: `std::unordered_map` <https://zh.cppreference.com/w/cpp/container/unordered_map> | ||
|
||
template<class k, class v> | ||
bool key_exists(std::map<k, v> const &map, k const &key) { | ||
// TODO: 实现函数 | ||
} | ||
|
||
template<class k, class v> | ||
void set(std::map<k, v> &map, k key, v value) { | ||
// TODO: 实现函数 | ||
} | ||
|
||
// ---- 不要修改以下代码 ---- | ||
int main(int argc, char **argv) { | ||
ASSERT(false, "todo!"); | ||
using namespace std::string_literals; | ||
|
||
std::map<std::string, std::string> secrets; | ||
|
||
set(secrets, "hello"s, "world"s); | ||
ASSERT(key_exists(secrets, "hello"s), "\"hello\" shoud be in `secrets`"); | ||
ASSERT(!key_exists(secrets, "foo"s), "\"foo\" shoud not be in `secrets`"); | ||
|
||
set(secrets, "foo"s, "bar"s); | ||
set(secrets, "Infini"s, "Tensor"s); | ||
ASSERT(secrets["hello"] == "world", "hello -> world"); | ||
ASSERT(secrets["foo"] == "bar", "foo -> bar"); | ||
ASSERT(secrets["Infini"] == "Tensor", "Infini -> Tensor"); | ||
|
||
set(secrets, "hello"s, "developer"s); | ||
ASSERT(secrets["hello"] == "developer", "hello -> developer"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
#include "../exercise.h" | ||
#include <algorithm> | ||
#include <string> | ||
#include <vector> | ||
|
||
// READ: `std::transform` <https://zh.cppreference.com/w/cpp/algorithm/transform> | ||
// READ: `std::vector::begin` <https://zh.cppreference.com/w/cpp/container/vector/begin> | ||
|
||
int main(int argc, char **argv) { | ||
ASSERT(false, "todo!"); | ||
std::vector<int> val{8, 13, 21, 34, 55}; | ||
// TODO: 调用 `std::transform`,将 `v` 中的每个元素乘以 2,并转换为字符串,存入 `ans` | ||
// std::vector<std::string> ans | ||
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"); | ||
ASSERT(ans[2] == "42", "ans[2] should be 42"); | ||
ASSERT(ans[3] == "68", "ans[3] should be 68"); | ||
ASSERT(ans[4] == "110", "ans[4] should be 110"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
#include "../exercise.h" | ||
#include <numeric> | ||
|
||
// READ: `std::accumulate` <https://zh.cppreference.com/w/cpp/algorithm/accumulate> | ||
|
||
int main(int argc, char **argv) { | ||
ASSERT(false, "todo!"); | ||
using DataType = float; | ||
int shape[]{1, 3, 224, 224}; | ||
// TODO: 调用 `std::accumulate` 计算 `shape` 的元素之积 | ||
// int size = | ||
ASSERT(size = 602112, "4x1x3x224x224 = 602112"); | ||
return 0; | ||
} |