From 9ed577f6836b9feddefc02df928ec71622b01f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20NGUYEN?= Date: Wed, 3 Apr 2024 01:48:19 +0200 Subject: [PATCH] feat(cyb): add the whole subject --- content/cyb/basic/index.md | 97 ++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 26 deletions(-) diff --git a/content/cyb/basic/index.md b/content/cyb/basic/index.md index ffee3b8..b92f52b 100644 --- a/content/cyb/basic/index.md +++ b/content/cyb/basic/index.md @@ -9,6 +9,10 @@ description: "Subjects about C language" This category shows training exercises about C language. For all questions, please ask on the BackToBasics' [Discord server](https://discord.gg/SJGWzkU2gd). +We cannot use the intranet, so there are somes given files. Please play the +game and do not read the test file. You can download it +[here](https://github.com/BackToBasicsEpita/CyberRef). + A Makefile is already given with these rules: - `basics`: compiles ; @@ -16,29 +20,6 @@ A Makefile is already given with these rules: - `check`: runs the testsuite ; - `clean`: removes all trash files. -Moreover, you must use the following header file `basics.h`: - -```c -#ifndef BASICS_H -#define BASICS_H - -#include - -struct pair -{ - int x; - int y; -}; - -void fizzbuzz(int n); -size_t my_strlen(char *s); -long binary_number(char str[]); -int hamming_distance(char *dna1, char *dna2); -int is_isogram(char *s); -struct pair move_robot(struct pair current, char *directions); - -#endif /* !BASICS_H */ -``` You are only allowed to uses the functions defined in the following headers: - stdio.h @@ -88,7 +69,7 @@ size_t my_strlen(char *s); ``` This functions returns the length of the string argument. The string can be -null. +null, and its size will be 0. # Binary number @@ -99,8 +80,72 @@ long binary_number(char str[]); ``` This function returns the integer in decimal corresponding to the binary number -given in argument. +given in argument. If a caracter does not correspond to a binary digit, return +-1. + +## Example + +The output of `binary_number("110")` is `6`. + +The output of `binary_number("This is not correct")` is `-1`. + +# Hamming Distance DNA + +You have to implement the following function: + +```c +int hamming_distance(char *dna1, char *dna2); +``` + +This function returns the number of differents characters between the two +strings given in arguments. + +We read DNA using the letters C,A,G and T. If there is another caracter than +the previous one, return -1. Moreover, if the size of the two parameters are +not equal, return -1. + +## Example + +The output of `hamming_distance("CAGT", "GAGT")` is `1`. + +# Isogram + +You have to implement the follwing function: + +```c +int is_isogram(char *s); +``` + +This function returns if the given string is an isogram. An isogram word or +sentence is a word or a phrase without a repetiting letter, however spaces and +non letter caracters are allowed to appear multiple times. + +## Example + +`House` is an isogram word, but `Test.` is not. + +# Move Robot + +You have to implement the following function: + +```c +struct pair move_robot(struct pair current, char *directions); +``` + +Moreover, you have to implement the `pair` structure with two integer: `x` and +`y`. + +This function moves a robot in the current coordinates on a grid from a string +of directions and returns the new coordinates of the robot. + +The string of directions corresponds to a string of operations done on the +robot: + +- `U` for up ; +- `L` for left ; +- `D` for down ; +- `R` for right. ## Example -The output of `my_strlen("110")` is `6`. +The output of `move_robot({1, 1}, "UL")` is the structure pair `{0, 2}`.