diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-26 23:17:36 +0200 |
| commit | 264ae2f047a53ffac92271e4609038d17605738e (patch) | |
| tree | 480c68814f822439850029df0e0249a2cafb8177 | |
| parent | ad9867052d496f2c2a7f120a512208fb4dd4e787 (diff) | |
| download | piscine-264ae2f047a53ffac92271e4609038d17605738e.tar.gz piscine-264ae2f047a53ffac92271e4609038d17605738e.tar.bz2 piscine-264ae2f047a53ffac92271e4609038d17605738e.zip | |
exam final
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> +#+ +:+ +#+ * |
