From 06b5b8f71487c156ba8be8ed4df80c71dd73a9df Mon Sep 17 00:00:00 2001 From: Allynixtor <97223164+Allynixtor@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:53:35 +1100 Subject: [PATCH] added sagas problems (#258) --- data/course-revision/1511-23T3/2d_malloc.mdx | 2 +- data/course-revision/1511-23T3/atoi.mdx | 49 ++++++++++++++++++++ data/course-revision/1511-23T3/strcmp.mdx | 49 ++++++++++++++++++++ data/course-revision/1511-23T3/strlen.mdx | 36 ++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 data/course-revision/1511-23T3/atoi.mdx create mode 100644 data/course-revision/1511-23T3/strcmp.mdx create mode 100644 data/course-revision/1511-23T3/strlen.mdx diff --git a/data/course-revision/1511-23T3/2d_malloc.mdx b/data/course-revision/1511-23T3/2d_malloc.mdx index 680b09c..9b87d7c 100644 --- a/data/course-revision/1511-23T3/2d_malloc.mdx +++ b/data/course-revision/1511-23T3/2d_malloc.mdx @@ -47,7 +47,7 @@ $ ./2d_malloc 10 10 When you think your program is working, you can use CSE autotest to test your solution. -```bash:~/1521-revision/2d_malloc +```bash:~/1511-revision/2d_malloc $ 1511 csesoc-autotest 2d_malloc ``` diff --git a/data/course-revision/1511-23T3/atoi.mdx b/data/course-revision/1511-23T3/atoi.mdx new file mode 100644 index 0000000..3c90b38 --- /dev/null +++ b/data/course-revision/1511-23T3/atoi.mdx @@ -0,0 +1,49 @@ +--- +title: atoi +desc: Implement the C stdlib function atoi +class: COMP1511 +difficulty: 2 +--- + +# atoi + +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. + +For example, + +``` +atoi("123") -> 123 +atoi("19") -> 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. + +Furthermore, once you have printed out all the command line arguments, you should print out the sum and product of all these arguments. + +The output from your program should look **exactly** like this: + +```bash:~/1511-revision/atoi +$ dcc atoi.c -o atoi +$ ./atoi 3 2 +3 +2 +5 6 +``` + +## Assumptions/Restrictions/Clarifications + +It is guaranteed that the command lines argument given in the autotest are numerical. + +You should not use the library implementation of `atoi` as that defeats the whole purpose of this exercise. + +## CSE Autotest + +When you think your program is working, you can use CSE autotest to test your solution. + +```bash:~/1511-revision/atoi +$ 1511 csesoc-autotest atoi +``` + +## Solution + +You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/atoi/solution.c). diff --git a/data/course-revision/1511-23T3/strcmp.mdx b/data/course-revision/1511-23T3/strcmp.mdx new file mode 100644 index 0000000..c294a50 --- /dev/null +++ b/data/course-revision/1511-23T3/strcmp.mdx @@ -0,0 +1,49 @@ +--- +title: strcmp +desc: Implement the C stdlib function strcmp +class: COMP1511 +difficulty: 2 +--- + +# strcmp + +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. + +`strcmp` works by sequentially going through both strings and comparing each character. +If `char 1` < `char 2`, then we would return `-1`. +If `char 1 > char 2`, then we would return `1`. + +However, If both strings equal each other, then we would return `0`. + +For example, + +``` +strcmp("hi", "hi") -> 0 +strcmp("a", "b") -> -1 +``` + +The output from your program should look **exactly** like this: + +```bash:~/1511-revision/strcmp +$ dcc strcmp.c -o strcmp +$ ./strcmp "hello" "hello" +0 +``` + +## Assumptions/Restrictions/Clarifications + +You should not use the library implementation of `strcmp` as that defeats the whole purpose of this exercise. + +It is guaranteed that your function is only expected to return `0`, `1`, and `-1`. + +## CSE Autotest + +When you think your program is working, you can use CSE autotest to test your solution. + +```bash:~/1511-revision/strcmp +$ 1511 csesoc-autotest strcmp +``` + +## Solution + +You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strcmp/solution.c). diff --git a/data/course-revision/1511-23T3/strlen.mdx b/data/course-revision/1511-23T3/strlen.mdx new file mode 100644 index 0000000..4562e79 --- /dev/null +++ b/data/course-revision/1511-23T3/strlen.mdx @@ -0,0 +1,36 @@ +--- +title: strlen +desc: Implement the C stdlib function strlen +class: COMP1511 +difficulty: 2 +--- + +# strlen + +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, + +```` +The output from your program should look **exactly** like this: +```bash:~/1511-revision/strlen +$ dcc strlen -o strlen +$ ./strlen "hi" +2 +```` + +## Assumptions/Restrictions/Clarifications + +You should not use the library implementation of `strlen` as that defeats the whole purpose of this exercise. + +Note that `strlen` does not count the null terminator `\0` as part of a string's length. + +## CSE Autotest + +When you think your program is working, you can use CSE autotest to test your solution. + +```bash:~/1511-revision/strlen +$ 1511 csesoc-autotest strlen +``` + +## Solution + +You can view the solution code to this problem [here](https://github.com/Allynixtor/comp1511-23T3-problems/blob/main/solutions/strlen/solution.c).