Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added sagas problems #258

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/course-revision/1511-23T3/2d_malloc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
49 changes: 49 additions & 0 deletions data/course-revision/1511-23T3/atoi.mdx
Original file line number Diff line number Diff line change
@@ -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).
49 changes: 49 additions & 0 deletions data/course-revision/1511-23T3/strcmp.mdx
Original file line number Diff line number Diff line change
@@ -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).
36 changes: 36 additions & 0 deletions data/course-revision/1511-23T3/strlen.mdx
Original file line number Diff line number Diff line change
@@ -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).