Skip to content

Commit 817cdc2

Browse files
committed
update: 添加题目
Signed-off-by: YdrMaster <[email protected]>
1 parent f2dc555 commit 817cdc2

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

exercises/00_hello_world/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <iostream>
22

33
int main(int argc, char **argv) {
4-
std::cout << "Hello world!" << std::endl;
4+
// TODO: 在控制台输出 "Hello, InfiniTensor!" 并换行
5+
std::cout << "Hello, InfiniTensor!" << std::endl;
56
return 0;
67
}

exercises/01_variable&add/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
3+
int main(int argc, char **argv) {
4+
// TODO: 补全变量定义并打印加法运算
5+
auto x = 1;
6+
std::cout << x << " + " << x << " = " << x + x << std::endl;
7+
return 0;
8+
}

exercises/02_function/main.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
3+
// NOTE: 这是函数声明
4+
int add(int, int);
5+
6+
int main(int argc, char **argv) {
7+
auto x = 1, y = 2;
8+
std::cout << x << " + " << y << " = " << add(x, y) << std::endl;
9+
return 0;
10+
}
11+
12+
// TODO: 补全函数定义
13+
int add(int a, int b) {
14+
return a + b;
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2+
3+
#include <iostream>
4+
5+
void func(int param) {
6+
std::cout << "befor add: " << param << std::endl;
7+
param += 1;
8+
std::cout << "after add: " << param << std::endl;
9+
}
10+
11+
int main(int argc, char **argv) {
12+
auto arg = 99;
13+
std::cout << "befor func call: " << arg << std::endl;
14+
func(arg);
15+
std::cout << "after func call: " << arg << std::endl;
16+
return 0;
17+
}

exercises/04_static/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2+
3+
#include <iostream>
4+
5+
void func(int param) {
6+
static int static_ = param;
7+
std::cout << "static_ = " << static_++ << std::endl;
8+
}
9+
10+
int main(int argc, char **argv) {
11+
func(5);
12+
func(4);
13+
func(3);
14+
func(2);
15+
func(1);
16+
return 0;
17+
}

exercises/05_constexpr/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2+
3+
#include <iostream>
4+
5+
constexpr int fibonacci(int i) {
6+
switch (i) {
7+
case 0:
8+
return 0;
9+
case 1:
10+
return 1;
11+
default:
12+
return fibonacci(i - 1) + fibonacci(i - 2);
13+
}
14+
}
15+
16+
int main(int argc, char **argv) {
17+
constexpr auto FIB25 = fibonacci(25);
18+
std::cout << "fibonacci(25) = " << FIB25 << std::endl;
19+
20+
auto fib30 = fibonacci(30);
21+
std::cout << "fibonacci(30) = " << fib30 << std::endl;
22+
23+
return 0;
24+
}

xmake.lua

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
add_rules("mode.debug", "mode.release")
2+
set_encodings("utf-8")
23

3-
target("00_hello_world")
4+
target("exercise00")
45
set_kind("binary")
56
add_files("exercises/00_hello_world/main.cpp")
7+
8+
target("exercise01")
9+
set_kind("binary")
10+
add_files("exercises/01_variable&add/main.cpp")
11+
12+
target("exercise02")
13+
set_kind("binary")
14+
add_files("exercises/02_function/main.cpp")
15+
16+
target("exercise03")
17+
set_kind("binary")
18+
add_files("exercises/03_argument&parameter/main.cpp")
19+
20+
target("exercise04")
21+
set_kind("binary")
22+
add_files("exercises/04_static/main.cpp")
23+
24+
target("exercise05")
25+
set_kind("binary")
26+
add_files("exercises/05_constexpr/main.cpp")

0 commit comments

Comments
 (0)