Skip to content

Commit eaa1b0d

Browse files
committed
solutions: ex006
1 parent e33e190 commit eaa1b0d

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

exercises/005_arrays2.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
//
1919
const std = @import("std");
2020

21+
//
22+
// todo x: 数组操作: 合并/重复元素/遍历
23+
//
2124
pub fn main() void {
2225
const le = [_]u8{ 1, 3 };
2326
const et = [_]u8{ 3, 7 };

exercises/006_strings.zig

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,31 @@
1818
//
1919
const std = @import("std");
2020

21+
//
22+
// todo x: strings 类型: = byte array. // 基本操作, 和数组操作一致
23+
//
2124
pub fn main() void {
2225
const ziggy = "stardust";
2326

24-
// (Problem 1)
27+
// todo x: (Problem 1)
2528
// Use array square bracket syntax to get the letter 'd' from
2629
// the string "stardust" above.
27-
const d: u8 = ziggy[???];
30+
const d: u8 = ziggy[4]; // todo x: 下标取元素
2831

29-
// (Problem 2)
32+
// todo x: (Problem 2)
3033
// Use the array repeat '**' operator to make "ha ha ha ".
31-
const laugh = "ha " ???;
34+
const laugh = "ha " ** 3;
3235

33-
// (Problem 3)
36+
// todo x: (Problem 3)
3437
// Use the array concatenation '++' operator to make "Major Tom".
3538
// (You'll need to add a space as well!)
3639
const major = "Major";
3740
const tom = "Tom";
38-
const major_tom = major ??? tom;
41+
const major_tom = major ++ " " ++ tom; // todo x: 字符串拼接
3942

4043
// That's all the problems. Let's see our results:
41-
std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });
44+
std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom }); // todo x: 字符串格式化方式
45+
4246
// Keen eyes will notice that we've put 'u' and 's' inside the '{}'
4347
// placeholders in the format string above. This tells the
4448
// print() function to format the values as a UTF-8 character and

patches/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# No Peeking! :-)
22

3+
- 这个目录是答案.
4+
- 😄 做不出来, 可以复查.
5+
- 不建议直接看答案.
6+
37
Welcome to the ziglings/patches directory. This is how ziglings is tested.
48

59
The patches fix the broken exercises so that they work again, which means the
@@ -26,7 +30,6 @@ $ zig build -Dhealed [step]
2630

2731
Éowyn tests all healed programs using this secret option.
2832

29-
3033
## Gollum
3134

3235
Another Bash shell script named `gollum.sh` may also be found. He snatches the

0 commit comments

Comments
 (0)