Skip to content

Commit 06b5b8f

Browse files
authored
added sagas problems (#258)
1 parent 7d6428a commit 06b5b8f

File tree

4 files changed

+135
-1
lines changed

4 files changed

+135
-1
lines changed

data/course-revision/1511-23T3/2d_malloc.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ ./2d_malloc 10 10
4747

4848
When you think your program is working, you can use CSE autotest to test your solution.
4949

50-
```bash:~/1521-revision/2d_malloc
50+
```bash:~/1511-revision/2d_malloc
5151
$ 1511 csesoc-autotest 2d_malloc
5252
```
5353

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: atoi
3+
desc: Implement the C stdlib function atoi
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
8+
# atoi
9+
10+
Your task is to implement the C Standard Library function `atoi`. `atoi` takes in a `const char *` that is guaranteed to be a numerical string, e.g. `"123"`, and returns the numerical form of that string.
11+
12+
For example,
13+
14+
```
15+
atoi("123") -> 123
16+
atoi("19") -> 19
17+
```
18+
19+
Your function should take in command line arguments (which are guaranteed to be numerical), and use your implementation of `atoi` to convert them into a number, and print it out.
20+
21+
Furthermore, once you have printed out all the command line arguments, you should print out the sum and product of all these arguments.
22+
23+
The output from your program should look **exactly** like this:
24+
25+
```bash:~/1511-revision/atoi
26+
$ dcc atoi.c -o atoi
27+
$ ./atoi 3 2
28+
3
29+
2
30+
5 6
31+
```
32+
33+
## Assumptions/Restrictions/Clarifications
34+
35+
It is guaranteed that the command lines argument given in the autotest are numerical.
36+
37+
You should not use the library implementation of `atoi` as that defeats the whole purpose of this exercise.
38+
39+
## CSE Autotest
40+
41+
When you think your program is working, you can use CSE autotest to test your solution.
42+
43+
```bash:~/1511-revision/atoi
44+
$ 1511 csesoc-autotest atoi
45+
```
46+
47+
## Solution
48+
49+
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/atoi/solution.c).
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: strcmp
3+
desc: Implement the C stdlib function strcmp
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
8+
# strcmp
9+
10+
Your task is to implement the C Standard Library function `strcmp`. `strcmp` takes in two `const char *` and returns an integer depending on the differences between the two strings.
11+
12+
`strcmp` works by sequentially going through both strings and comparing each character.
13+
If `char 1` < `char 2`, then we would return `-1`.
14+
If `char 1 > char 2`, then we would return `1`.
15+
16+
However, If both strings equal each other, then we would return `0`.
17+
18+
For example,
19+
20+
```
21+
strcmp("hi", "hi") -> 0
22+
strcmp("a", "b") -> -1
23+
```
24+
25+
The output from your program should look **exactly** like this:
26+
27+
```bash:~/1511-revision/strcmp
28+
$ dcc strcmp.c -o strcmp
29+
$ ./strcmp "hello" "hello"
30+
0
31+
```
32+
33+
## Assumptions/Restrictions/Clarifications
34+
35+
You should not use the library implementation of `strcmp` as that defeats the whole purpose of this exercise.
36+
37+
It is guaranteed that your function is only expected to return `0`, `1`, and `-1`.
38+
39+
## CSE Autotest
40+
41+
When you think your program is working, you can use CSE autotest to test your solution.
42+
43+
```bash:~/1511-revision/strcmp
44+
$ 1511 csesoc-autotest strcmp
45+
```
46+
47+
## Solution
48+
49+
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strcmp/solution.c).
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: strlen
3+
desc: Implement the C stdlib function strlen
4+
class: COMP1511
5+
difficulty: 2
6+
---
7+
8+
# strlen
9+
10+
Your task is to implement the C Standard Library function `strlen`. `strlen` takes in a `const char *` and returns an integer that is the length of the given string,
11+
12+
````
13+
The output from your program should look **exactly** like this:
14+
```bash:~/1511-revision/strlen
15+
$ dcc strlen -o strlen
16+
$ ./strlen "hi"
17+
2
18+
````
19+
20+
## Assumptions/Restrictions/Clarifications
21+
22+
You should not use the library implementation of `strlen` as that defeats the whole purpose of this exercise.
23+
24+
Note that `strlen` does not count the null terminator `\0` as part of a string's length.
25+
26+
## CSE Autotest
27+
28+
When you think your program is working, you can use CSE autotest to test your solution.
29+
30+
```bash:~/1511-revision/strlen
31+
$ 1511 csesoc-autotest strlen
32+
```
33+
34+
## Solution
35+
36+
You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strlen/solution.c).

0 commit comments

Comments
 (0)