diff options
55 files changed, 1802 insertions, 0 deletions
diff --git a/exam_final/rendu/__GIT_HISTORY b/exam_final/rendu/__GIT_HISTORY new file mode 100755 index 0000000..6286ca2 --- /dev/null +++ b/exam_final/rendu/__GIT_HISTORY @@ -0,0 +1,122 @@ +commit 34f8b0fa88a10c6066047c6fd5902a1f61fb7139 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 17:45:42 2019 +0200 + + brainfuck + + brainfuck/brainfuck.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ + brainfuck/stack.c | 42 +++++++++++++++++++++++++ + brainfuck/stack.h | 26 ++++++++++++++++ + 3 files changed, 153 insertions(+) + +commit b3f3fe0a53e3b5dfe186cbf50701ff9047f37705 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 16:39:24 2019 +0200 + + ord_alphlong + + ord_alphlong/helper.c | 52 ++++++++++++++++++++++++++++++++++ + ord_alphlong/helper2.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ + ord_alphlong/helper3.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ + ord_alphlong/include.h | 42 +++++++++++++++++++++++++++ + ord_alphlong/main.c | 32 +++++++++++++++++++++ + 5 files changed, 278 insertions(+) + +commit 80849735bdeb1452a6275fee2594b1407e9afcce +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 14:31:26 2019 +0200 + + count_alpha + + count_alpha/count_alpha.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 109 insertions(+) + +commit e198992e2e0673e33fecd38897f3fc41b186c82c +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 13:34:08 2019 +0200 + + sort_list + + sort_list/sort_list.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 49 insertions(+) + +commit 2f7b14a42f21d2598b99d668cbd75c121fa0e28e +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 13:09:52 2019 +0200 + + ft_split + + ft_split/ft_split.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 74 insertions(+) + +commit 1b5c95b498c6286a77677a1c101a8208e56af4ce +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 12:33:28 2019 +0200 + + ft_itoa + + ft_itoa/ft_itoa.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 64 insertions(+) + +commit 329e7a2c15e26d350d651af2571829c2a25c0666 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 11:33:31 2019 +0200 + + ft_atoi + + ft_atoi/ft_atoi.c | 38 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 38 insertions(+) + +commit cb2d8246d609fc0d347f19124e57e516f2360c59 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 11:09:08 2019 +0200 + + last_word + + last_word/last_word.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +commit 93bec2c03948516c977dc726ebcbd29d1cf87af2 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:41:13 2019 +0200 + + ft_strrev + + ft_strrev/ft_strrev.c | 40 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +commit 22e59a40561ff53f5f65d90d48d7061bfc4f9280 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:32:44 2019 +0200 + + rotone + + rotone/rotone.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 50 insertions(+) + +commit 41aa95d06869add95fa1078bd18b1d58122fa011 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:14:58 2019 +0200 + + aff_last_param + + aff_last_param/aff_last_param.c | 31 +++++++++++++++++++++++++++++++ + 1 file changed, 31 insertions(+) + +commit a338cec36af53b43e95ff0de679288068b212a22 +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:08:09 2019 +0200 + + ft_putstr + + ft_putstr/ft_putstr.c | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +commit de79154201b309ec32e35f5a26dc675a3c4e0b1e +Author: Exam 42 <exam-no-reply@42.fr> +Date: Fri Jul 26 10:05:03 2019 +0200 + + aff_z + + aff_z/aff_z.c | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) diff --git a/exam_final/rendu/aff_last_param/aff_last_param.c b/exam_final/rendu/aff_last_param/aff_last_param.c new file mode 100755 index 0000000..27a024a --- /dev/null +++ b/exam_final/rendu/aff_last_param/aff_last_param.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* aff_last_param.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:09:02 by exam #+# #+# */ +/* Updated: 2019/07/26 10:13:09 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int main(int argc, char **argv) +{ + if (argc != 1) + write(1, argv[argc - 1], ft_strlen(argv[argc - 1])); + write(1, "\n", 1); + return (0); +} diff --git a/exam_final/rendu/aff_z/aff_z.c b/exam_final/rendu/aff_z/aff_z.c new file mode 100755 index 0000000..3cb7625 --- /dev/null +++ b/exam_final/rendu/aff_z/aff_z.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* aff_z.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:00:33 by exam #+# #+# */ +/* Updated: 2019/07/26 10:02:22 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + write(STDOUT_FILENO, "z\n", 2); + return (0); +} diff --git a/exam_final/rendu/brainfuck/brainfuck.c b/exam_final/rendu/brainfuck/brainfuck.c new file mode 100755 index 0000000..4cd619d --- /dev/null +++ b/exam_final/rendu/brainfuck/brainfuck.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* brainfuck.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 16:42:44 by exam #+# #+# */ +/* Updated: 2019/07/26 17:43:25 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "stack.h" +#include <stdlib.h> +#include <unistd.h> + +void go_close(char **str) +{ + t_stack *st; + + st = create_elem(**str); + while (st != NULL) + { + (*str)++; + if (**str == '[') + st = push(st, '['); + if (**str == ']') + st = pop(st); + } +} + +void go_open(char **str) +{ + t_stack *st; + + st = create_elem(**str); + while (st != NULL) + { + (*str)--; + if (**str == ']') + st = push(st, ']'); + if (**str == '[') + st = pop(st); + } +} + +int main(int argc, char **argv) +{ + char *ptr; + char *origin; + char *str; + int i; + + if (argc != 2) + { + write(1, "\n", 1); + return (0); + } + origin = (char*)malloc(2048); + ptr = origin; + i = 0; + while (i < 2048) + ptr[i++] = 0; + str = argv[1]; + while (*str) + { + if (*str == '>') + ptr++; + else if (*str == '<') + ptr--; + else if (*str == '+') + (*ptr)++; + else if (*str == '-') + (*ptr)--; + else if (*str == '.') + write(1, ptr, 1); + else if (*str == '[' && *ptr == 0) + go_close(&str); + else if (*str == ']' && *ptr != 0) + go_open(&str); + str++; + } + free(origin); + return (0); +} diff --git a/exam_final/rendu/brainfuck/stack.c b/exam_final/rendu/brainfuck/stack.c new file mode 100755 index 0000000..c79c039 --- /dev/null +++ b/exam_final/rendu/brainfuck/stack.c @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 17:28:55 by exam #+# #+# */ +/* Updated: 2019/07/26 17:40:35 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "stack.h" + +t_stack *create_elem(char data) +{ + t_stack *elem; + + elem = malloc(sizeof(t_stack)); + elem->data = data; + elem->next = NULL; + return (elem); +} + +t_stack *push(t_stack *stack, char data) +{ + t_stack *elem; + + elem = create_elem(data); + elem->next = stack; + return (elem); +} + +t_stack *pop(t_stack *stack) +{ + t_stack *tmp; + + tmp = stack->next; + free(stack); + return (tmp); +} diff --git a/exam_final/rendu/brainfuck/stack.h b/exam_final/rendu/brainfuck/stack.h new file mode 100755 index 0000000..6d0d57b --- /dev/null +++ b/exam_final/rendu/brainfuck/stack.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 17:33:37 by exam #+# #+# */ +/* Updated: 2019/07/26 17:39:15 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STACK_H +# define STACK_H + +typedef struct s_stack +{ + char data; + struct s_stack *next; +} t_stack; + +t_stack *push(t_stack *stack, char data); +t_stack *create_elem(char data); +t_stack *pop(t_stack *stack); + +#endif diff --git a/exam_final/rendu/count_alpha/count_alpha.c b/exam_final/rendu/count_alpha/count_alpha.c new file mode 100755 index 0000000..ed502a5 --- /dev/null +++ b/exam_final/rendu/count_alpha/count_alpha.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* count_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 13:36:33 by exam #+# #+# */ +/* Updated: 2019/07/26 14:30:23 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdio.h> +#include <unistd.h> + +typedef struct s_counter +{ + char letter; + int count; +} t_counter; + +int in_counters(t_counter *counters, char c) +{ + int i; + + i = 0; + while (counters[i].letter) + { + if (c == counters[i].letter) + return (1); + i++; + } + return (0); +} + +void str_tolow(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + *str += 'a' - 'A'; + str++; + } +} + +int count_char(char c, char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (c == *str) + counter++; + str++; + } + return (counter); +} + +void print_counters(t_counter *counters, int size) +{ + int i; + + i = 0; + while (i < size) + { + if (counters[i].count != 0) + { + printf("%d%c", counters[i].count, counters[i].letter); + if (i != size - 1) + printf(", "); + } + i++; + } +} + +int main(int argc, char **argv) +{ + t_counter counters[26]; + int i; + int j; + + if (argc == 2) + { + i = 0; + j = 0; + while (i < 26) + { + counters[i].letter = '\0'; + counters[i].count = 0; + i++; + } + str_tolow(argv[1]); + i = 0; + while (argv[1][i]) + { + if (argv[1][i] >= 'a' && argv[1][i] <= 'z' && !in_counters(counters, argv[1][i])) + { + counters[j].letter = argv[1][i]; + counters[j].count = count_char(argv[1][i], argv[1]); + j++; + } + i++; + } + print_counters(counters, j); + } + printf("\n"); + return (0); +} diff --git a/exam_final/rendu/ft_atoi/ft_atoi.c b/exam_final/rendu/ft_atoi/ft_atoi.c new file mode 100755 index 0000000..2f125bf --- /dev/null +++ b/exam_final/rendu/ft_atoi/ft_atoi.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 11:11:42 by exam #+# #+# */ +/* Updated: 2019/07/26 11:32:51 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(const char *str) +{ + int nb; + int is_negative; + + while (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r' + || *str == '\v' || *str == '\f'|| *str == '\r') + str++; + is_negative = 0; + if (*str == '+' || *str == '-') + { + if (*str == '-') + is_negative = 1; + str++; + } + nb = 0; + while (*str >= '0' && *str <= '9') + { + nb *= 10; + nb += *str - '0'; + str++; + } + if (is_negative) + nb = -nb; + return (nb); +} diff --git a/exam_final/rendu/ft_itoa/ft_itoa.c b/exam_final/rendu/ft_itoa/ft_itoa.c new file mode 100755 index 0000000..308cb41 --- /dev/null +++ b/exam_final/rendu/ft_itoa/ft_itoa.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 11:35:43 by exam #+# #+# */ +/* Updated: 2019/07/26 12:32:57 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int count_len(int nbr) +{ + int counter; + unsigned int u_nbr; + + if (nbr == 0) + return (1); + counter = 0; + u_nbr = nbr; + if (nbr < 0) + { + counter++; + u_nbr = -nbr; + } + while (u_nbr > 0) + { + u_nbr /= 10; + counter++; + } + return (counter); +} + +char *ft_itoa(int nbr) +{ + char *str; + int len; + int is_negative; + unsigned int u_nbr; + + len = count_len(nbr); + if ((str = (char*)malloc(sizeof(char) * (len + 1))) == NULL) + return (NULL); + str[len] = '\0'; + is_negative = 0; + u_nbr = nbr; + if (nbr < 0) + { + is_negative = 1; + str[0] = '-'; + u_nbr = -nbr; + } + len--; + while (len >= (is_negative ? 1 : 0)) + { + str[len] = u_nbr % 10 + '0'; + u_nbr /= 10; + len--; + } + return (str); +} diff --git a/exam_final/rendu/ft_putstr/ft_putstr.c b/exam_final/rendu/ft_putstr/ft_putstr.c new file mode 100755 index 0000000..3733591 --- /dev/null +++ b/exam_final/rendu/ft_putstr/ft_putstr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:05:51 by exam #+# #+# */ +/* Updated: 2019/07/26 10:07:27 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +void ft_putstr(char *str) +{ + while (*str) + write(STDOUT_FILENO, str++, 1); +} diff --git a/exam_final/rendu/ft_split/ft_split.c b/exam_final/rendu/ft_split/ft_split.c new file mode 100755 index 0000000..75d9f8d --- /dev/null +++ b/exam_final/rendu/ft_split/ft_split.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 12:35:48 by exam #+# #+# */ +/* Updated: 2019/07/26 13:09:10 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> + +int in_charset(char c) +{ + return (c == ' ' || c == '\n' || c == '\t'); +} + +int count_segment(char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (in_charset(*str)) + { + str++; + continue ; + } + counter++; + while (*str && !in_charset(*str)) + str++; + } + return (counter); +} + +char **ft_split(char *str) +{ + char **strs; + char *tmp; + int size; + int i; + int j; + + size = count_segment(str); + if ((strs = (char**)malloc(sizeof(char*) * (size + 1))) == NULL) + return (NULL); + i = 0; + while (i < size) + { + if (*str && in_charset(*str)) + { + str++; + continue ; + } + j = 0; + while (str[j] && !in_charset(str[j])) + j++; + if ((tmp = (char*)malloc(sizeof(char) * (j + 1))) == NULL) + return (NULL); + j = 0; + while (*str && !in_charset(*str)) + { + tmp[j] = *str++; + j++; + } + tmp[j] = '\0'; + strs[i++] = tmp; + } + strs[i] = NULL; + return (strs); +} diff --git a/exam_final/rendu/ft_strrev/ft_strrev.c b/exam_final/rendu/ft_strrev/ft_strrev.c new file mode 100755 index 0000000..685dd70 --- /dev/null +++ b/exam_final/rendu/ft_strrev/ft_strrev.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrev.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:34:13 by exam #+# #+# */ +/* Updated: 2019/07/26 10:40:13 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +char *ft_strrev(char *str) +{ + int i; + int j; + char tmp; + + i = 0; + j = ft_strlen(str) - 1; + while (i < j) + { + tmp = str[i]; + str[i] = str[j]; + str[j] = tmp; + i++; + j--; + } + return (str); +} diff --git a/exam_final/rendu/last_word/last_word.c b/exam_final/rendu/last_word/last_word.c new file mode 100755 index 0000000..f8bdb11 --- /dev/null +++ b/exam_final/rendu/last_word/last_word.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* last_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:42:10 by exam #+# #+# */ +/* Updated: 2019/07/26 11:05:51 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int is_space(char c) +{ + return (c == ' ' || c == '\t'); +} + +int main(int argc, char **argv) +{ + int i; + + if (argc == 2) + { + i = ft_strlen(argv[1]) - 1; + while (i > -1 && is_space(argv[1][i])) + i--; + while (i > -1 && !is_space(argv[1][i])) + i--; + i++; + while (i >= 0 && argv[1][i] && !is_space(argv[1][i])) + { + write(1, &argv[1][i], 1); + i++; + } + } + write(1, "\n", 1); + return (0); +} diff --git a/exam_final/rendu/ord_alphlong/helper.c b/exam_final/rendu/ord_alphlong/helper.c new file mode 100755 index 0000000..7d285c1 --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 14:40:48 by exam #+# #+# */ +/* Updated: 2019/07/26 16:35:08 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include <unistd.h> +#include "include.h" + +int ft_strlen(char *str) +{ + int counter; + + counter = 0; + while (str[counter]) + counter++; + return (counter); +} + +int letter_diff(char a, char b) +{ + if (b >= 'A' && b <= 'Z') + b += 'a' - 'A'; + if (a >= 'A' && a <= 'Z') + a += 'a' - 'A'; + return (a - b); +} + +void ft_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +int str_lettercmp(char *s1, char *s2) +{ + if (ft_strlen(s1) != ft_strlen(s2)) + return (-1); + while (*s1 && *s2 && letter_diff(*s1, *s2) == 0) + { + s1++; + s2++; + } + return (letter_diff(*s1, *s2)); +} diff --git a/exam_final/rendu/ord_alphlong/helper2.c b/exam_final/rendu/ord_alphlong/helper2.c new file mode 100755 index 0000000..431274b --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper2.c @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 15:20:07 by exam #+# #+# */ +/* Updated: 2019/07/26 16:29:42 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "include.h" + +int sorted(char **strs, int cmp(char*, char*)) +{ + int i; + + i = 0; + if (strs[0] == NULL) + return (1); + while (strs[i + 1] != NULL) + { + if ((*cmp)(strs[i], strs[i + 1]) > 0) + return (0); + i++; + } + return (1); +} + +void sort_strs(char **strs, int cmp(char*, char*)) +{ + int i; + char *tmp; + + while (!sorted(strs, cmp)) + { + i = 0; + while (strs[i + 1] != NULL) + { + if ((*cmp)(strs[i], strs[i + 1]) > 0) + { + tmp = strs[i]; + strs[i] = strs[i + 1]; + strs[i + 1] = tmp; + } + i++; + } + } +} + +int strlen_cmp(char *s1, char *s2) +{ + return (ft_strlen(s1) - ft_strlen(s2)); +} + +void print_strs(char **strs) +{ + int i; + int len; + + i = 0; + while (strs[i] != NULL) + { + len = ft_strlen(strs[i]); + while (strs[i] && ft_strlen(strs[i]) == len) + { + ft_putstr(strs[i]); + if (strs[i + 1] != NULL && ft_strlen(strs[i + 1]) == len) + ft_putstr(" "); + else + ft_putstr("\n"); + i++; + } + } +} diff --git a/exam_final/rendu/ord_alphlong/helper3.c b/exam_final/rendu/ord_alphlong/helper3.c new file mode 100755 index 0000000..83b548a --- /dev/null +++ b/exam_final/rendu/ord_alphlong/helper3.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* helper3.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 16:34:01 by exam #+# #+# */ +/* Updated: 2019/07/26 16:34:28 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "include.h" + +int in_charset(char c) +{ + return (c == ' ' || c == '\t'); +} + +int count_segment(char *str) +{ + int counter; + + counter = 0; + while (*str) + { + if (in_charset(*str)) + { + str++; + continue ; + } + counter++; + while (*str && !in_charset(*str)) + str++; + } + return (counter); +} + +char **ft_split(char *str) +{ + char **strs; + char *tmp; + int size; + int i; + int j; + + size = count_segment(str); + if ((strs = (char**)malloc(sizeof(char*) * (size + 1))) == NULL) + return (NULL); + i = 0; + while (i < size) + { + if (*str && in_charset(*str)) + { + str++; + continue ; + } + j = 0; + while (str[j] && !in_charset(str[j])) + j++; + if ((tmp = (char*)malloc(sizeof(char) * (j + 1))) == NULL) + return (NULL); + j = 0; + while (*str && !in_charset(*str)) + { + tmp[j] = *str++; + j++; + } + tmp[j] = '\0'; + strs[i++] = tmp; + } + strs[i] = NULL; + return (strs); +} diff --git a/exam_final/rendu/ord_alphlong/include.h b/exam_final/rendu/ord_alphlong/include.h new file mode 100755 index 0000000..ac171fa --- /dev/null +++ b/exam_final/rendu/ord_alphlong/include.h @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* include.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 14:44:30 by exam #+# #+# */ +/* Updated: 2019/07/26 16:34:49 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef INCLUDE_H +# define INCLUDE_H + +/* +** helper.c +*/ + +int ft_strlen(char *str); +int letter_diff(char a, char b); +int str_lettercmp(char *s1, char *s2); +void ft_putstr(char *str); + +/* +** helper2.c +*/ + +int sorted(char **strs, int cmp(char*, char*)); +void sort_strs(char **strs, int cmp(char*, char*)); +int strlen_cmp(char *s1, char *s2); +void print_strs(char **strs); + +/* +** helper3.c +*/ + +int in_charset(char c); +int count_segment(char *str); +char **ft_split(char *str); + +#endif diff --git a/exam_final/rendu/ord_alphlong/main.c b/exam_final/rendu/ord_alphlong/main.c new file mode 100755 index 0000000..5a46015 --- /dev/null +++ b/exam_final/rendu/ord_alphlong/main.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 14:37:24 by exam #+# #+# */ +/* Updated: 2019/07/26 16:33:22 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> +#include <stdlib.h> +#include "include.h" + +#include <stdio.h> +int main(int argc, char **argv) +{ + char **strs; + + if (argc != 2) + { + write(1, "\n", 1); + return (0); + } + strs = ft_split(argv[1]); + sort_strs(strs, &strlen_cmp); + sort_strs(strs, &str_lettercmp); + print_strs(strs); + return (0); +} diff --git a/exam_final/rendu/rotone/rotone.c b/exam_final/rendu/rotone/rotone.c new file mode 100755 index 0000000..e5fafdf --- /dev/null +++ b/exam_final/rendu/rotone/rotone.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rotone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 10:15:47 by exam #+# #+# */ +/* Updated: 2019/07/26 10:27:46 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <unistd.h> + +int is_upper(char c) +{ + return (c >= 'A' && c <= 'Z'); +} + +int is_lower(char c) +{ + return (c >= 'a' && c <= 'z'); +} + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +int main(int argc, char **argv) +{ + int i; + + if (argc == 2) + { + i = 0; + while (argv[1][i]) + { + if (is_lower(argv[1][i])) + ft_putchar((argv[1][i] - 'a' + 1) % 26 + 'a'); + else if (is_upper(argv[1][i])) + ft_putchar((argv[1][i] - 'A' + 1) % 26 + 'A'); + else + ft_putchar(argv[1][i]); + i++; + } + } + write(1, "\n", 1); + return (0); +} diff --git a/exam_final/rendu/sort_list/sort_list.c b/exam_final/rendu/sort_list/sort_list.c new file mode 100755 index 0000000..62c173b --- /dev/null +++ b/exam_final/rendu/sort_list/sort_list.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/26 13:11:16 by exam #+# #+# */ +/* Updated: 2019/07/26 13:33:27 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include <stdlib.h> +#include "list.h" + +static int sorted(t_list *lst, int (*cmp)(int, int)) +{ + if (lst == NULL) + return (1); + while (lst->next != NULL) + { + if ((*cmp)(lst->data, lst->next->data) == 0) + return (0); + lst = lst->next; + } + return (1); +} + +t_list *sort_list(t_list* lst, int (*cmp)(int, int)) +{ + t_list *cursor; + int tmp; + + while (!sorted(lst, cmp)) + { + cursor = lst; + while (cursor->next != NULL) + { + if ((*cmp)(cursor->data, cursor->next->data) == 0) + { + tmp = cursor->data; + cursor->data = cursor->next->data; + cursor->next->data = tmp; + } + cursor = cursor->next; + } + } + return (lst); +} diff --git a/exam_final/subjects/0-0-aff_z/examples.txt b/exam_final/subjects/0-0-aff_z/examples.txt new file mode 100644 index 0000000..f15ada3 --- /dev/null +++ b/exam_final/subjects/0-0-aff_z/examples.txt @@ -0,0 +1,8 @@ +$> ./aff_z "abc" | cat -e +z$ +$> ./aff_z "dubO a POIL" | cat -e +z$ +$> ./aff_z "zaz sent le poney" | cat -e +z$ +$> ./aff_z | cat -e +z$ diff --git a/exam_final/subjects/0-0-aff_z/subject.en.txt b/exam_final/subjects/0-0-aff_z/subject.en.txt new file mode 100644 index 0000000..e11a0b3 --- /dev/null +++ b/exam_final/subjects/0-0-aff_z/subject.en.txt @@ -0,0 +1,21 @@ +Assignment name : aff_z +Expected files : aff_z.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Write a program that takes a string, and displays the first 'z' +character it encounters in it, followed by a newline. If there are no +'z' characters in the string, the program writes 'z' followed +by a newline. If the number of parameters is not 1, the program displays +'z' followed by a newline. + +Example: + +$> ./aff_z "abc" | cat -e +z$ +$> ./aff_z "RaInB0w d4Sh!" | cat -e +z$ +$> ./aff_z "ThE C4k3 Is a L|3" | cat -e +z$ +$> ./aff_z | cat -e +z$
\ No newline at end of file diff --git a/exam_final/subjects/0-0-aff_z/subject.fr.txt b/exam_final/subjects/0-0-aff_z/subject.fr.txt new file mode 100644 index 0000000..196702e --- /dev/null +++ b/exam_final/subjects/0-0-aff_z/subject.fr.txt @@ -0,0 +1,22 @@ +Assignment name : aff_z +Expected files : aff_z.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Écrire un programme qui prend en paramètre une chaîne de caractères, et qui +affiche sur la sortie standard le premier caractère 'z' rencontré dans +cette chaîne, suivi de '\n'. Si aucun 'z' +n'est rencontré dans la chaîne, le programme affiche 'z' suivi de +'\n'. Si le nombre de paramètres est différent de 1, le +programme affiche 'z' suivi de '\n'. + +Exemple: + +$> ./aff_z "abc" | cat -e +z$ +$> ./aff_z "dubO a POIL" | cat -e +z$ +$> ./aff_z "zaz sent le poney" | cat -e +z$ +$> ./aff_z | cat -e +z$ diff --git a/exam_final/subjects/1-0-ft_putstr/subject.en.txt b/exam_final/subjects/1-0-ft_putstr/subject.en.txt new file mode 100644 index 0000000..243e4d8 --- /dev/null +++ b/exam_final/subjects/1-0-ft_putstr/subject.en.txt @@ -0,0 +1,13 @@ +Assignment name : ft_putstr +Expected files : ft_putstr.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Write a function that displays a string on the standard output. + +The pointer passed to the function contains the address of the string's first +character. + +Your function must be declared as follows: + +void ft_putstr(char *str); diff --git a/exam_final/subjects/1-0-ft_putstr/subject.fr.txt b/exam_final/subjects/1-0-ft_putstr/subject.fr.txt new file mode 100644 index 0000000..94183ee --- /dev/null +++ b/exam_final/subjects/1-0-ft_putstr/subject.fr.txt @@ -0,0 +1,12 @@ +Assignment name : ft_putstr +Expected files : ft_putstr.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Écrire une fonction qui affiche une chaîne de caractères sur la sortie standard. + +Le pointeur passé à la fonction est l'adresse du premier caractère de la chaîne. + +Elle devra être prototypée de la façon suivante : + +void ft_putstr(char *str); diff --git a/exam_final/subjects/10-0-count_alpha/subject.en.txt b/exam_final/subjects/10-0-count_alpha/subject.en.txt new file mode 100644 index 0000000..a057f70 --- /dev/null +++ b/exam_final/subjects/10-0-count_alpha/subject.en.txt @@ -0,0 +1,25 @@ +Assignment name : count_alpha +Expected files : count_alpha.c +Allowed functions: write, printf +-------------------------------------------------------------------------------- + +Write a program called count_alpha that takes a string and displays the number +of occurences of its alphabetical characters. Other characters are not counted. +The order is the order of occurence in the string. The display must be ended by +a newline. + +The format is in the examples. + +If the number of arguments is not 1, display only a newline. + +Examples : +$> ./count_alpha abbcc +1a, 2b, 2c +$> ./count_alpha "abbcc" +1a, 2b, 2c +$> ./count_alpha "abbcc" "dddeef" | cat -e +$ +$> ./count_alpha "My Hyze 47y 7." | cat -e +1m, 3y, 1h, 1z, 1e$ +$> ./count_alpha "" | cat -e +$ diff --git a/exam_final/subjects/10-0-count_alpha/subject.fr.txt b/exam_final/subjects/10-0-count_alpha/subject.fr.txt new file mode 100644 index 0000000..0971bc4 --- /dev/null +++ b/exam_final/subjects/10-0-count_alpha/subject.fr.txt @@ -0,0 +1,24 @@ +Assignment name : count_alpha +Expected files : count_alpha.c +Allowed functions: write, printf +-------------------------------------------------------------------------------- + +Écrire un programme count_alpha qui prend une chaîne et affiche le nombre d'occurences +de ses caractères alphabétiques. Les autres caractères ne sont pas comptés. L'ordre est l'ordre d'apparition dans la chaîne. +L'affichage doit être terminé par un newline. + +Le format est dans les exemples. + +Si le nombre d'arguments n'est pas 1, afficher juste un newline. + +Exemples : +$> ./count_alpha abbcc +1a, 2b, 2c +$> ./count_alpha "abbcc" +1a, 2b, 2c +$> ./count_alpha "abbcc" "dddeef" | cat -e +$ +$> ./count_alpha "My Hyze 47y 7." | cat -e +1m, 3y, 1h, 1z, 1e$ +$> ./count_alpha "" | cat -e +$ diff --git a/exam_final/subjects/11-0-ord_alphlong/examples.txt b/exam_final/subjects/11-0-ord_alphlong/examples.txt new file mode 100644 index 0000000..c89eefd --- /dev/null +++ b/exam_final/subjects/11-0-ord_alphlong/examples.txt @@ -0,0 +1,18 @@ +$>./ord_alphlong +$ +$>./ord_alphlong "De son baton il frappa la pierre et l eau jaillit" | cat -e +l$ +De et il la$ +eau son$ +baton$ +frappa pierre$ +jaillit$ +$>./ord_alphlong "A a b B cc ca cd" | cat -e +A a b B$ +ca cc cd$ +$>./ord_alphlong "Pour l Imperium de l humanite" | cat -e +l l$ +de$ +Pour$ +humanite Imperium$ +$> diff --git a/exam_final/subjects/11-0-ord_alphlong/subject.en.txt b/exam_final/subjects/11-0-ord_alphlong/subject.en.txt new file mode 100644 index 0000000..118a1ca --- /dev/null +++ b/exam_final/subjects/11-0-ord_alphlong/subject.en.txt @@ -0,0 +1,40 @@ +Assignment name : ord_alphlong +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Write a program that takes a string as a parameter and prints its words sorted +in length order then in alphabetical order: when words are alphabetically +equals (for example aA and Aa), original order must remain (lower and upper +case are the same in alphabetical order). If there are duplicates, they must +remain. + +If number of parameters is different from 1, the program prints +\n. + +There will be only spaces, tabs and alphanumeric caracters in strings. + +You'll print only one space between each word. Nothing before the first and +after the last word of each line. + +Examples: + +$>./ord_alphlong +$ +$>./ord_alphlong "After all this time Always said Snape" | cat -e +all$ +said this time$ +After Snape$ +Always$ +$>./ord_alphlong "A a b B cc ca cd" | cat -e +A a b B$ +ca cc cd$ +$>./ord_alphlong "Never take a gamble you are not prepared to lose" | cat -e +a$ +to$ +are not you$ +lose take$ +Never$ +gamble$ +prepared$ +$> diff --git a/exam_final/subjects/11-0-ord_alphlong/subject.fr.txt b/exam_final/subjects/11-0-ord_alphlong/subject.fr.txt new file mode 100644 index 0000000..047ea4c --- /dev/null +++ b/exam_final/subjects/11-0-ord_alphlong/subject.fr.txt @@ -0,0 +1,41 @@ +Assignment name : ord_alphlong +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Écrire un programme qui prend en paramètre une chaîne de caractères et qui +affiche les mots de cette chaîne par ordre de longueur puis dans l'ordre +alphabétique, avec une petite variante: En cas d'égalité alphabétique (par +exemple aA et Aa) les mots doivent rester dans l'ordre où ils +étaient dans la chaîne d'origine (Les majuscules et minuscules sont identiques +dans l'ordre alphabétique). En cas de doublons, les doublons sont conservés. + +Si le nombre de paramètres transmis est différent de 1, le programme affiche +\n. + +Dans les chaînes, il n'y aura que des espaces, des tabulations et des +caractères alphanumériques. + +Vous n'afficherez qu'un espace entre les mots. Aucun avant le premier ni après +le dernier de chaque ligne. + +Exemples: + +$>./ord_alphlong +$ +$>./ord_alphlong "De son baton il frappa la pierre et l eau jaillit" | cat -e +l$ +De et il la$ +eau son$ +baton$ +frappa pierre$ +jaillit$ +$>./ord_alphlong "A a b B cc ca cd" | cat -e +A a b B$ +ca cc cd$ +$>./ord_alphlong "Pour l Imperium de l humanite" | cat -e +l l$ +de$ +Pour$ +humanite Imperium$ +$> diff --git a/exam_final/subjects/12-0-brainfuck/examples.txt b/exam_final/subjects/12-0-brainfuck/examples.txt new file mode 100644 index 0000000..b5bc38a --- /dev/null +++ b/exam_final/subjects/12-0-brainfuck/examples.txt @@ -0,0 +1,6 @@ +$>./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e +Hello World!$ +$>./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e +Hi$ +$>./brainfuck | cat -e +$ diff --git a/exam_final/subjects/12-0-brainfuck/subject.en.txt b/exam_final/subjects/12-0-brainfuck/subject.en.txt new file mode 100644 index 0000000..a926e71 --- /dev/null +++ b/exam_final/subjects/12-0-brainfuck/subject.en.txt @@ -0,0 +1,32 @@ +Assignment name : brainfuck +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Write a Brainfuck interpreter program. +The source code will be given as first parameter. +The code will always be valid, with no more than 4096 operations. +Brainfuck is a minimalist language. It consists of an array of bytes +(in our case, let's say 2048 bytes) initialized to zero, +and a pointer to its first byte. + +Every operator consists of a single character : +- '>' increment the pointer ; +- '<' decrement the pointer ; +- '+' increment the pointed byte ; +- '-' decrement the pointed byte ; +- '.' print the pointed byte on standard output ; +- '[' go to the matching ']' if the pointed byte is 0 (while start) ; +- ']' go to the matching '[' if the pointed byte is not 0 (while end). + +Any other character is a comment. + +Examples: + +$>./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-] +>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e +Hello World!$ +$>./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e +Hi$ +$>./brainfuck | cat -e +$ diff --git a/exam_final/subjects/12-0-brainfuck/subject.fr.txt b/exam_final/subjects/12-0-brainfuck/subject.fr.txt new file mode 100644 index 0000000..2a15973 --- /dev/null +++ b/exam_final/subjects/12-0-brainfuck/subject.fr.txt @@ -0,0 +1,32 @@ +Assignment name : brainfuck +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Écrire un programme capable d'interpréter du Brainfuck. +Le code source sera passé en premier paramètre. +Le code transmis sera toujours valide, et ne comportera pas plus de 4096 opérations. +Le Brainfuck est un langage minimaliste constitué d'un tableau d'octets +(dans le cadre de cet exercice, 2048 octets) tous initialisés à 0, +et d'un pointeur sur son premier octet. + +Voici les différents opérateurs du Brainfuck : +- '>' incrémente le pointeur ; +- '<' décrémente le pointeur ; +- '+' incrémente l'octet pointé ; +- '-' décrémente l'octet pointé ; +- '.' affiche l'octet pointé sur la sortie standard ; +- '[' va au ']' correspondant si l'octet pointé est égal à 0 (début de boucle) ; +- ']' va au '[' correspondant si l'octet pointé est différent de 0 (fin de boucle). + +Tout autre caractère est un commentaire. + +Exemples: + +$>./brainfuck "++++++++++[>+++++++>++++++++++>+++>+<<<<-] +>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." | cat -e +Hello World!$ +$>./brainfuck "+++++[>++++[>++++H>+++++i<<-]>>>++\n<<<<-]>>--------.>+++++.>." | cat -e +Hi$ +$>./brainfuck | cat -e +$ diff --git a/exam_final/subjects/13-0-infin_add/examples.txt b/exam_final/subjects/13-0-infin_add/examples.txt new file mode 100644 index 0000000..79fffd5 --- /dev/null +++ b/exam_final/subjects/13-0-infin_add/examples.txt @@ -0,0 +1,7 @@ +$> ./infin_add "879879087" "67548976597" | cat -e +68428855684$ +$> ./infin_add "-876435" "987143265" | cat -e +986266830$ +$> ./infin_add "-807965" "-34532" +-842497 +$> diff --git a/exam_final/subjects/13-0-infin_add/subject.en.txt b/exam_final/subjects/13-0-infin_add/subject.en.txt new file mode 100644 index 0000000..a531aa1 --- /dev/null +++ b/exam_final/subjects/13-0-infin_add/subject.en.txt @@ -0,0 +1,24 @@ +Assignment name : infin_add +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Write a program that takes as a parameter two strings that represent two +numbers potentially infinit, and displays on stdout the result of the addition +of these two numbers, followed by a '\n'. + +A negative number will always be prefixed by one and only one -. The only +characters that can be part of the strings are digits and the sign -. + +Both parameters will always be well formated, and you will always have +exactly two parameters, no tricks. + +Example: + +$> ./infin_add "879879087" "67548976597" | cat -e +68428855684$ +$> ./infin_add "-876435" "987143265" | cat -e +986266830$ +$> ./infin_add "-807965" "-34532" +-842497 +$> diff --git a/exam_final/subjects/13-0-infin_add/subject.fr.txt b/exam_final/subjects/13-0-infin_add/subject.fr.txt new file mode 100644 index 0000000..3f780f8 --- /dev/null +++ b/exam_final/subjects/13-0-infin_add/subject.fr.txt @@ -0,0 +1,25 @@ +Assignment name : infin_add +Expected files : *.c, *.h +Allowed functions: write, malloc, free +-------------------------------------------------------------------------------- + +Écrire un programme qui prend en paramètres deux chaînes de caractères +représentant des nombres de longueur potentiellement infinie, et affiche sur la +sortie standard le résultat de l'addition de ces deux nombres, suivi d'un '\n'. + +Un nombre négatif sera précédé d'un et un seul signe -. Les seuls +caractères qui feront potentiellement partie de ces chaînes sont les chiffres +et le signe -. + +Tous les paramètres seront bien formatés, et il y a toujours exactement deux +paramètres, pas de pièges. + +Exemple: + +$> ./infin_add "879879087" "67548976597" | cat -e +68428855684$ +$> ./infin_add "-876435" "987143265" | cat -e +986266830$ +$> ./infin_add "-807965" "-34532" +-842497 +$> diff --git a/exam_final/subjects/2-0-aff_last_param/subject.en.txt b/exam_final/subjects/2-0-aff_last_param/subject.en.txt new file mode 100644 index 0000000..847abfe --- /dev/null +++ b/exam_final/subjects/2-0-aff_last_param/subject.en.txt @@ -0,0 +1,18 @@ +Assignment name : aff_last_param +Expected files : aff_last_param.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Write a program that takes strings as arguments, and displays its last +argument followed by a newline. + +If the number of arguments is less than 1, the program displays a newline. + +Examples: + +$> ./aff_last_param "Zelda" "is" "a" "boy" | cat -e +boy$ +$> ./aff_last_param "I read this on internet !" | cat -e +I read this on internet !$ +$> ./aff_last_param | cat -e +$ diff --git a/exam_final/subjects/2-0-aff_last_param/subject.fr.txt b/exam_final/subjects/2-0-aff_last_param/subject.fr.txt new file mode 100644 index 0000000..d1de6f0 --- /dev/null +++ b/exam_final/subjects/2-0-aff_last_param/subject.fr.txt @@ -0,0 +1,17 @@ +Assignment name : aff_last_param +Expected files : aff_last_param.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Écrire un programme qui prend des chaînes, et affiche son dernier argument suivi d'un newline. + +S'il y a moins d'un argument, le programme affiche juste un newline. + +Exemples: + +$> ./aff_last_param "zaz" "mange" "des" "chats" | cat -e +chats$ +$> ./aff_last_param "j'aime le savon" | cat -e +j'aime le savon$ +$> ./aff_last_param | cat -e +$ diff --git a/exam_final/subjects/3-0-rotone/examples.txt b/exam_final/subjects/3-0-rotone/examples.txt new file mode 100644 index 0000000..b8db87f --- /dev/null +++ b/exam_final/subjects/3-0-rotone/examples.txt @@ -0,0 +1,12 @@ +$>./rotone "abc" +bcd +$>./rotone "Les stagiaires du staff ne sentent pas toujours tres bon." | cat -e +Mft tubhjbjsft ev tubgg of tfoufou qbt upvkpvst usft cpo.$ +$>./rotone "AkjhZ zLKIJz , 23y " | cat -e +BlkiA aMLJKa , 23z $ +$>./rotone | cat -e +$ +$> +$>./rotone "" | cat -e +$ +$> diff --git a/exam_final/subjects/3-0-rotone/subject.en.txt b/exam_final/subjects/3-0-rotone/subject.en.txt new file mode 100644 index 0000000..093fc7a --- /dev/null +++ b/exam_final/subjects/3-0-rotone/subject.en.txt @@ -0,0 +1,28 @@ +Assignment name : rotone +Expected files : rotone.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Write a program that takes a string and displays it, replacing each of its +letters by the next one in alphabetical order. + +'z' becomes 'a' and 'Z' becomes 'A'. Case remains unaffected. + +The output will be followed by a \n. + +If the number of arguments is not 1, the program displays \n. + +Example: + +$>./rotone "abc" +bcd +$>./rotone "Les stagiaires du staff ne sentent pas toujours tres bon." | cat -e +Mft tubhjbjsft ev tubgg of tfoufou qbt upvkpvst usft cpo.$ +$>./rotone "AkjhZ zLKIJz , 23y " | cat -e +BlkiA aMLJKa , 23z $ +$>./rotone | cat -e +$ +$> +$>./rotone "" | cat -e +$ +$> diff --git a/exam_final/subjects/3-0-rotone/subject.fr.txt b/exam_final/subjects/3-0-rotone/subject.fr.txt new file mode 100644 index 0000000..07e5004 --- /dev/null +++ b/exam_final/subjects/3-0-rotone/subject.fr.txt @@ -0,0 +1,31 @@ +Assignment name : rotone +Expected files : rotone.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Écrire un programme nommé rotone, qui prend en paramètre une chaîne de +caractères, et qui affiche cette chaîne en remplaçant chaque caractère +alphabétique par le caractère suivant dans l'ordre alphabétique. + +'z' devient 'a' et 'Z' devient 'A'. Les majuscules restent des majuscules, les +minuscules restent des minuscules. + +L'affichage se termine toujours par un retour à la ligne. + +Si le nombre de paramètres transmis est différent de 1, le programme affiche +'\n'. + +Exemple: + +$>./rotone "abc" +bcd +$>./rotone "Les stagiaires du staff ne sentent pas toujours tres bon." | cat -e +Mft tubhjbjsft ev tubgg of tfoufou qbt upvkpvst usft cpo.$ +$>./rotone "AkjhZ zLKIJz , 23y " | cat -e +BlkiA aMLJKa , 23z $ +$>./rotone | cat -e +$ +$> +$>./rotone "" | cat -e +$ +$> diff --git a/exam_final/subjects/4-0-ft_strrev/subject.en.txt b/exam_final/subjects/4-0-ft_strrev/subject.en.txt new file mode 100644 index 0000000..6c31580 --- /dev/null +++ b/exam_final/subjects/4-0-ft_strrev/subject.en.txt @@ -0,0 +1,12 @@ +Assignment name : ft_strrev +Expected files : ft_strrev.c +Allowed functions: +-------------------------------------------------------------------------------- + +Write a function that reverses a string by modifying it. + +It must return its parameter. + +Your function must be declared as follows: + +char *ft_strrev(char *str); diff --git a/exam_final/subjects/4-0-ft_strrev/subject.fr.txt b/exam_final/subjects/4-0-ft_strrev/subject.fr.txt new file mode 100644 index 0000000..f6eb115 --- /dev/null +++ b/exam_final/subjects/4-0-ft_strrev/subject.fr.txt @@ -0,0 +1,12 @@ +Assignment name : ft_strrev +Expected files : ft_strrev.c +Allowed functions: +-------------------------------------------------------------------------------- + +Écrire une fonction qui inverse une chaîne de caractères en la modifiant. + +Elle devra renvoyer son paramètre. + +Votre fonction devra être prototypée de la façon suivante : + +char *ft_strrev(char *str); diff --git a/exam_final/subjects/5-0-last_word/examples.txt b/exam_final/subjects/5-0-last_word/examples.txt new file mode 100644 index 0000000..63250f2 --- /dev/null +++ b/exam_final/subjects/5-0-last_word/examples.txt @@ -0,0 +1,11 @@ +$> ./last_word "FOR PONY" | cat -e +PONY$ +$> ./last_word "this ... is sparta, then again, maybe not" | cat -e +not$ +$> ./last_word " " | cat -e +$ +$> ./last_word "a" "b" | cat -e +$ +$> ./last_word " lorem,ipsum " | cat -e +lorem,ipsum$ +$> diff --git a/exam_final/subjects/5-0-last_word/subject.en.txt b/exam_final/subjects/5-0-last_word/subject.en.txt new file mode 100644 index 0000000..35d242c --- /dev/null +++ b/exam_final/subjects/5-0-last_word/subject.en.txt @@ -0,0 +1,25 @@ +Assignment name : last_word +Expected files : last_word.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Write a program that takes a string and displays its last word followed by a \n. + +A word is a section of string delimited by spaces/tabs or by the start/end of +the string. + +If the number of parameters is not 1, or there are no words, display a newline. + +Example: + +$> ./last_word "FOR PONIES" | cat -e +PONIES$ +$> ./last_word "this ... is sparta, then again, maybe not" | cat -e +not$ +$> ./last_word " " | cat -e +$ +$> ./last_word "a" "b" | cat -e +$ +$> ./last_word " lorem,ipsum " | cat -e +lorem,ipsum$ +$> diff --git a/exam_final/subjects/5-0-last_word/subject.fr.txt b/exam_final/subjects/5-0-last_word/subject.fr.txt new file mode 100644 index 0000000..a488c2e --- /dev/null +++ b/exam_final/subjects/5-0-last_word/subject.fr.txt @@ -0,0 +1,27 @@ +Assignment name : last_word +Expected files : last_word.c +Allowed functions: write +-------------------------------------------------------------------------------- + +Écrire un programme qui prend une chaîne de caractères en paramètre, et qui +affiche le dernier mot de cette chaîne, suivi d'un '\n'. + +On appelle "mot" une portion de chaîne de caractères délimitée soit par des +espaces et/ou des tabulations, soit par le début / fin de la chaîne. + +Si le nombre de paramètres transmis est différent de 1, ou s'il n'y a aucun mot +à afficher, le programme affiche '\n'. + +Exemple: + +$> ./last_word "FOR PONY" | cat -e +PONY$ +$> ./last_word "this ... is sparta, then again, maybe not" | cat -e +not$ +$> ./last_word " " | cat -e +$ +$> ./last_word "a" "b" | cat -e +$ +$> ./last_word " lorem,ipsum " | cat -e +lorem,ipsum$ +$> diff --git a/exam_final/subjects/6-0-ft_atoi/subject.en.txt b/exam_final/subjects/6-0-ft_atoi/subject.en.txt new file mode 100644 index 0000000..ebfe92b --- /dev/null +++ b/exam_final/subjects/6-0-ft_atoi/subject.en.txt @@ -0,0 +1,13 @@ +Assignment name : ft_atoi +Expected files : ft_atoi.c +Allowed functions: None +-------------------------------------------------------------------------------- + +Write a function that converts the string argument str to an integer (type int) +and returns it. + +It works much like the standard atoi(const char *str) function, see the man. + +Your function must be declared as follows: + +int ft_atoi(const char *str); diff --git a/exam_final/subjects/6-0-ft_atoi/subject.fr.txt b/exam_final/subjects/6-0-ft_atoi/subject.fr.txt new file mode 100644 index 0000000..2c9977c --- /dev/null +++ b/exam_final/subjects/6-0-ft_atoi/subject.fr.txt @@ -0,0 +1,12 @@ +Assignment name : ft_atoi +Expected files : ft_atoi.c +Allowed functions: None +-------------------------------------------------------------------------------- + +Écrire une fonction qui convertit une chaîne en un entier (type int) et le retourne. + +Marche comme la fonction standard atoi(const char *str), voir le man. + +La fonction doit être prototypée comme suit: + +int ft_atoi(const char *str); diff --git a/exam_final/subjects/7-0-ft_itoa/subject.en.txt b/exam_final/subjects/7-0-ft_itoa/subject.en.txt new file mode 100644 index 0000000..54bf901 --- /dev/null +++ b/exam_final/subjects/7-0-ft_itoa/subject.en.txt @@ -0,0 +1,11 @@ +Assignment name : ft_itoa +Expected files : ft_itoa.c +Allowed functions: malloc +-------------------------------------------------------------------------------- + +Write a function that takes an int and converts it to a null-terminated string. +The function returns the result in a char array that you must allocate. + +Your function must be declared as follows: + +char *ft_itoa(int nbr); diff --git a/exam_final/subjects/7-0-ft_itoa/subject.fr.txt b/exam_final/subjects/7-0-ft_itoa/subject.fr.txt new file mode 100644 index 0000000..6acf5df --- /dev/null +++ b/exam_final/subjects/7-0-ft_itoa/subject.fr.txt @@ -0,0 +1,12 @@ +Assignment name : ft_itoa +Expected files : ft_itoa.c +Allowed functions: malloc +-------------------------------------------------------------------------------- + +Écrire une fonction qui prend un int et le convertit en chaîne terminée par un +caractère nul. Cette fonction retourne le résultat en tant qu'un tableau de +char que vous devez allouer. + +Votre fonction sera déclarée comme suit: + +char *ft_itoa(int nbr); diff --git a/exam_final/subjects/8-0-ft_split/subject.en.txt b/exam_final/subjects/8-0-ft_split/subject.en.txt new file mode 100644 index 0000000..97375e9 --- /dev/null +++ b/exam_final/subjects/8-0-ft_split/subject.en.txt @@ -0,0 +1,14 @@ +Assignment name : ft_split +Expected files : ft_split.c +Allowed functions: malloc +-------------------------------------------------------------------------------- + +Write a function that takes a string, splits it into words, and returns them as +a NULL-terminated array of strings. + +A "word" is defined as a part of a string delimited either by spaces/tabs/new +lines, or by the start/end of the string. + +Your function must be declared as follows: + +char **ft_split(char *str); diff --git a/exam_final/subjects/8-0-ft_split/subject.fr.txt b/exam_final/subjects/8-0-ft_split/subject.fr.txt new file mode 100644 index 0000000..acd1b41 --- /dev/null +++ b/exam_final/subjects/8-0-ft_split/subject.fr.txt @@ -0,0 +1,16 @@ +Assignment name : ft_split +Expected files : ft_split.c +Allowed functions: malloc +-------------------------------------------------------------------------------- + +Écrire une fonction qui prend en paramètre une chaîne de caractères et la +découpe en mots, qui seront retournés sous la forme d'un tableau de chaînes +terminé par NULL. + +On appelle "mot" une portion de chaîne de caractères délimitée soit par des +espaces, des retours à la ligne et/ou des tabulations, soit par le début / fin +de la chaîne. + +Votre fonction devra être prototypée de la façon suivante : + +char **ft_split(char *str); diff --git a/exam_final/subjects/9-0-sort_list/list.h b/exam_final/subjects/9-0-sort_list/list.h new file mode 100644 index 0000000..34a3677 --- /dev/null +++ b/exam_final/subjects/9-0-sort_list/list.h @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: zaz <zaz@staff.42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2014/02/27 13:14:10 by zaz #+# #+# */ +/* Updated: 2014/02/27 13:15:29 by zaz ### ########.fr */ +/* */ +/* ************************************************************************** */ + +typedef struct s_list t_list; + +struct s_list +{ + int data; + t_list *next; +}; diff --git a/exam_final/subjects/9-0-sort_list/subject.en.txt b/exam_final/subjects/9-0-sort_list/subject.en.txt new file mode 100644 index 0000000..13d9a15 --- /dev/null +++ b/exam_final/subjects/9-0-sort_list/subject.en.txt @@ -0,0 +1,32 @@ +Assignment name : sort_list +Expected files : sort_list.c +Allowed functions: +-------------------------------------------------------------------------------- + +Write the following function: + +t_list *sort_list(t_list* lst, int (*cmp)(int, int)); + +This function must sort the list given as a parameter, using the function +pointer cmp to select the order to apply, and returns a pointer to the +first element of the sorted list. + +Duplications must remain. + +Inputs will always be consistent. + +You must use the type t_list described in the file list.h +that is provided to you. You must include that file +(#include "list.h"), but you must not turn it in. We will use our own +to compile your assignment. + +Functions passed as cmp will always return a value different from +0 if a and b are in the right order, 0 otherwise. + +For example, the following function used as cmp will sort the list +in ascending order: + +int ascending(int a, int b) +{ + return (a <= b); +} diff --git a/exam_final/subjects/9-0-sort_list/subject.fr.txt b/exam_final/subjects/9-0-sort_list/subject.fr.txt new file mode 100644 index 0000000..235c66c --- /dev/null +++ b/exam_final/subjects/9-0-sort_list/subject.fr.txt @@ -0,0 +1,32 @@ +Assignment name : sort_list +Expected files : sort_list.c +Allowed functions: +-------------------------------------------------------------------------------- + +Écrire la fonction suivante: + +t_list *sort_list(t_list* lst, int (*cmp)(int, int)); + +Cette fonction doit trier la liste passée en premier paramètre, en utilisant le +pointeur sur fonction cmp pour déterminer l'ordre à appliquer, et +renvoyer un pointeur vers le premier élément de la liste triée. + +Les doublons doivent être préservés. + +Les entrées seront toujours cohérentes. + +Vous devez utiliser le type t_list décrit dans le fichier list.h qui vous est +fourni. Vous devrez inclure (#include "list.h") ce fichier, mais ne pas le +rendre. Nous utiliserons le notre pour compiler votre exercice. + +Les fonctions passées en tant que cmp renverront toujours une valeur +différente de 0 si a et b sont dans le bon ordre, +dans le cas contraire elles renverront 0. + +Par exemple, la fonction suivante utilisée en tant que cmp devra +permettre de trier la liste par ordre croissant: + +int croissant(int a, int b) +{ + return (a <= b); +} |
