This commit is contained in:
Tanguy MAZE
2019-06-22 18:23:35 +02:00
commit f9e508d5ef
173 changed files with 6727 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
Assignment name : brackets
Expected files : *.c *.h
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes an undefined number of strings in arguments. For each
argument, the program prints on the standard output "OK" followed by a newline
if the expression is correctly bracketed, otherwise it prints "Error" followed by
a newline.
Symbols considered as 'brackets' are brackets '(' and ')', square brackets '['
and ']'and braces '{' and '}'. Every other symbols are simply ignored.
An opening bracket must always be closed by the good closing bracket in the
correct order. A string which not contains any bracket is considered as a
correctly bracketed string.
If there is no arguments, the program must print only a newline.
Examples :
$> ./brackets '(johndoe)' | cat -e
OK$
$> ./brackets '([)]' | cat -e
Error$
$> ./brackets '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e
OK$
OK$
$> ./brackets | cat -e
$
$>

View File

@@ -0,0 +1,32 @@
Assignment name : brackets
Expected files : *.c *.h
Allowed functions: write
--------------------------------------------------------------------------------
Ecrire un programme qui prendra une chaine de caractères en paramètre et qui
écrit sur la sortie standard 'OK' si l'expression est bien parenthesée et
'Error' dans le cas contraire, le tout suivi d'une newline.
Les symboles utilisés comme 'parenthèses' seront les parenthèses '(' et ')', les
crochets '[' et ']' ainsi que les accolades '{' et '}'. Tous les autres
caractères seront tout simplement ignorés.
Une parenthèse ouvrante devra obligatoirement être fermée par une parenthèse
fermante et dans le bon ordre (parenthèses imbriquées). Une chaine ne comportant
aucune parenthèse est considerée comme bien parenthesée.
Votre programme évaluera tous les arguments. Si aucun argument n'est fourni,
il affichera seulement une newline.
Exemples :
$> ./brackets '(jo:qahndoe)' | cat -e
OK$
$> ./brackets '([)]' | cat -e
Error$
$> ./brackets '' '{[(0 + 0)(1 + 1)](3*(-1)){()}}' | cat -e
OK$
OK$
$> ./brackets | cat -e
$
$>

View File

@@ -0,0 +1,28 @@
Assignment name : cycle_detector
Expected files : cycle_detector.c
Allowed functions: malloc, free
--------------------------------------------------------------------------------
Create a function named cycle_detector that takes a const t_list *list
as argument, and check if the given linked list contains no cycles.
A cycle is defined when you go at least twice through the same link, when you
travel inside a linked list.
This function should returnw 1 if it detects a cycle inside the given linked
list, otherwise it returns 0.
This function should be prototyped like this:
int cycle_detector(const t_list *list)
The type t_list is:
typedef struct s_list
{
int data;
struct s_list *next;
} t_list;
This type will be included in a header named "list.h". You don't have to turn-in
your "list.h", we will use ours during the evaluation.

View File

@@ -0,0 +1,28 @@
Assignment name : cycle_detector
Expected files : cycle_detector.c
Allowed functions: malloc, free
--------------------------------------------------------------------------------
Créez une fonction cycle_detector qui prends un "const t_list *list" en
argument, qui vérifiera qu'il n'y a aucun cycle à l'intérieur de la liste chainée
list.
Un cycle est défini quand, lors du parcours de la liste, vous passez au moins 2
fois à travers le même maillon.
Cette fonction retournera 1 si la fonction détecte un cycle, sinon elle renverra 0.
Cette fonction sera prototypé comme suit :
int cycle_detector(const t_list *list)
Le type "t_list" est défini comme suit :
typedef struct s_list
{
int data;
struct s_list *next;
} t_list;
Ce type sera fourni dans le header "list.h". Vous n'avez pas besoin de le fournir,
nous utiliserons le notre en correction.

View File

@@ -0,0 +1,50 @@
Assignment name : rpn_calc
Expected files : *.c, *.h
Allowed functions: atoi, printf, write, malloc, free
--------------------------------------------------------------------------------
Write a program that takes a string which contains an equation written in
Reverse Polish notation (RPN) as its first argument, evaluates the equation, and
prints the result on the standard output followed by a newline.
Reverse Polish Notation is a mathematical notation in which every operator
follows all of its operands. In RPN, every operator encountered evaluates the
previous 2 operands, and the result of this operation then becomes the first of
the two operands for the subsequent operator. Operands and operators must be
spaced by at least one space.
You must implement the following operators : "+", "-", "*", "/", and "%".
If the string isn't valid or there isn't exactly one argument, you must print
"Error" on the standard output followed by a newline.
All the given operands must fit in a "int".
Examples of formulas converted in RPN:
3 + 4 >> 3 4 +
((1 * 2) * 3) - 4 >> 1 2 * 3 * 4 - ou 3 1 2 * * 4 -
50 * (5 - (10 / 9)) >> 5 10 9 / - 50 *
Here's how to evaluate a formula in RPN:
1 2 * 3 * 4 -
2 3 * 4 -
6 4 -
2
Or:
3 1 2 * * 4 -
3 2 * 4 -
6 4 -
2
Examples:
$> ./rpn_calc "1 2 * 3 * 4 +" | cat -e
10$
$> ./rpn_calc "1 2 3 4 +" | cat -e
Error$
$> ./rpn_calc |cat -e
Error$

View File

@@ -0,0 +1,51 @@
Assignment name : rpn_calc
Expected files : *.c, *.h
Allowed functions: atoi, printf, write, malloc, free
--------------------------------------------------------------------------------
Ecrivez un programme qui prend en premier argument une chaine de caractères
correspondant à une équation écrite en Notation Polonaise Inverse ou NPI,
l'évalue et retourne le résultat sur la sortie standard suivi d'une newline.
La Notation Polonaise Inverse est un système d'écriture d'opérations arithméti-
ques qui consiste à placer les opérandes avant les opérateurs de telle
sorte que pour chaque opérateur rencontré, les 2 opérandes précédents soient
évalués et le résultat placé en lieu et place dans l'ordre de calcul. Les
opérandes et les opérateurs doivent avoir au moins un espace entre eux.
Vous devrez implémenter les opérateurs "+", "-", "*", "/" et "%".
Si la chaine de caractères n'est pas valide ou qu'il n'y a pas un seul argument,
vous devrez afficher "Error" sur la sortie standard, suivie d'une newline.
Tous les opérandes de la chaine de caracteres doivent pouvoir etre contenus
dans un int.
Exemple de formules converties en NPI :
3 + 4 >> 3 4 +
((1 * 2) * 3) - 4 >> 1 2 * 3 * 4 - ou 3 1 2 * * 4 -
50 * (5 - (10 / 9)) >> 5 10 9 / - 50 *
Décomposition d'un calcul en NPI :
1 2 * 3 * 4 - (On évalue "1 2 *" et on remplace l'ensemble par 2)
2 3 * 4 - (On évalue "2 3 *" et on remplace l'ensemble par 6)
6 4 - (On évalue "6 4 -" et on remplace l'ensemble par 2)
2
ou
3 1 2 * * 4 - (On évalue "1 2 *" et on remplace l'ensemble par 2)
3 2 * 4 - (On évalue "3 2 *" et on remplace l'ensemble par 6)
6 4 - (On évalue "6 4 -" et on remplace l'ensemble par 2)
2
Exemples :
$> ./rpn_calc "1 2 * 3 * 4 +" | cat -e
10$
$> ./rpn_calc "1 2 3 4 +" | cat -e
Error$
$> ./rpn_calc |cat -e
Error$