archi124
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//###############################
|
||||
// ATTENTION CE CODE EST MOCHE #
|
||||
//###############################
|
||||
|
||||
char most_frequent(const char *str){
|
||||
|
||||
//max
|
||||
//temp max
|
||||
//
|
||||
//lettre
|
||||
//temp lettre
|
||||
//index
|
||||
//index_clc
|
||||
|
||||
|
||||
char *cha = malloc(2 * sizeof(char));
|
||||
//{ lettre, temp}
|
||||
if (cha == NULL) return 0;
|
||||
|
||||
*cha = 0; // lettre
|
||||
*(cha + 1) = 0; //lettre pendant le clc
|
||||
|
||||
int *values = malloc (4 * sizeof(int));
|
||||
if(values == NULL) return 0 ;
|
||||
//{ max, temp max, index, index_clc}
|
||||
|
||||
*values = 0; // Maximum
|
||||
*(values + 1) = 0; // Max temporaire
|
||||
*(values + 2) = 0; // Index de la chaine
|
||||
*(values + 3) = 0; // Index de calcul
|
||||
|
||||
//deplacement (index de la chaine)
|
||||
while (*(str + *(values + 2)) != '\0'){
|
||||
|
||||
*(cha + 1) = *(str + *(values + 2)); //Traitement de la lettre à l'index x
|
||||
*(values + 1) = 0; // RESET du max de clc
|
||||
*(values + 3) = 0; // RESET de l'index de clc
|
||||
|
||||
//calcul pas du tt opti mais bon
|
||||
while (*(str + *(values + 3)) != '\0'){
|
||||
|
||||
//si la lettre en traitment est la mm que celle rencontree
|
||||
if (*(cha + 1) == *(str + *(values + 3))) {
|
||||
(*(values + 1)) ++;
|
||||
}
|
||||
|
||||
(*(values + 3)) ++;
|
||||
}
|
||||
|
||||
if (*values < *(values + 1)) {
|
||||
*values = *(values + 1); // temp -> max
|
||||
*cha = *(cha + 1);
|
||||
}
|
||||
|
||||
(*(values + 2)) ++;
|
||||
}
|
||||
free(values);
|
||||
return *cha;
|
||||
}
|
||||
/*
|
||||
int main () {
|
||||
|
||||
char test = most_frequent("WRYYYY!1!"); // 'Y'
|
||||
printf("%c\n", test);
|
||||
|
||||
test = most_frequent("ORA ORA ORA!"); // 'O'
|
||||
printf("%c\n",test);
|
||||
test = most_frequent("hello warudo!"); // 'l'
|
||||
printf("%c\n", test);
|
||||
most_frequent("oRA ora oRa?"); // 'o'
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
//utiliser la recu ?
|
||||
//possible mais avec fct aux
|
||||
//malloc dans my_factor puis appelle aux (poineur, n)
|
||||
int *my_factor(int n){
|
||||
|
||||
if (n <= 0) return NULL;
|
||||
if (n == 1) return 1;
|
||||
|
||||
int cnt = 0;
|
||||
int tmp = n;
|
||||
int div = 2;
|
||||
|
||||
while(tmp > 1){
|
||||
if (tmp % div == 0){
|
||||
cnt ++;
|
||||
tmp = tmp /div
|
||||
}
|
||||
else div ++;
|
||||
}
|
||||
|
||||
int *rslt = malloc((cnt + 1)* sizeof(int));
|
||||
if(rslt == NULL) return NULL;
|
||||
|
||||
int index = 0;
|
||||
int *kebab = rslt;
|
||||
tmp = n;
|
||||
div = 2;
|
||||
|
||||
while (temps > 1) {
|
||||
if (tmp % div == 0){
|
||||
*(kebab + index) = div;
|
||||
index ++;
|
||||
tmp = tmp / div;
|
||||
}
|
||||
else div ++;
|
||||
}
|
||||
|
||||
*kebab = 0;
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
char *strdup(const char *s);
|
||||
|
||||
|
||||
void my_strapp(char *src, char **dest){
|
||||
|
||||
if (src == NULL || dest == NULL) return;
|
||||
|
||||
//taille src
|
||||
int index = 0;
|
||||
while (*(src + index)) index ++;
|
||||
|
||||
//taille desti
|
||||
int index_dest = 0;
|
||||
while (*(*dest + index_dest)) index_dest ++;
|
||||
|
||||
//realloc des dest avec la taille de src
|
||||
*dest = realloc(*dest, index + index_dest + 1);
|
||||
//int *dest = realloc(*dest, index);
|
||||
|
||||
if (dest == NULL) return;
|
||||
|
||||
index = 0;
|
||||
/*while(*(new + index_dest)){
|
||||
|
||||
printf("%c", *(new + index_dest));
|
||||
|
||||
index_dest ++;
|
||||
}
|
||||
printf("\n");
|
||||
//index_dest --;
|
||||
while(*(src + index)){
|
||||
|
||||
*(new + (index_dest+ index)) = *(src + index);
|
||||
index ++;
|
||||
}*/
|
||||
|
||||
while(*(src + index)){
|
||||
*(*dest + index_dest + index) = *(src + index);
|
||||
index ++;
|
||||
}
|
||||
|
||||
*(dest + index_dest + index + 1) = '\0';
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
int main(){
|
||||
|
||||
char *src = strdup("World!");
|
||||
char *dest = strdup("Hello, ");
|
||||
char **dest_ptr = &dest;
|
||||
|
||||
my_strapp(src, dest_ptr); // Hello, World!
|
||||
printf("%s", *dest_ptr);
|
||||
free(src);
|
||||
free(dest);
|
||||
}*/
|
||||
|
||||
@@ -6,45 +6,54 @@ char *my_weirddup(char *src){
|
||||
if(src == NULL) return NULL;
|
||||
|
||||
int index = 0;
|
||||
while(*(src)){
|
||||
while(*(src + index)){
|
||||
index ++;
|
||||
src ++;
|
||||
}
|
||||
|
||||
char *str = malloc(index + 1);
|
||||
char *str = malloc(index);
|
||||
if(str == NULL) return NULL;
|
||||
|
||||
//src = 0;
|
||||
//printf("test");
|
||||
|
||||
char lettre = ' ';
|
||||
index = 0;
|
||||
|
||||
while (*src){
|
||||
lettre = *src;
|
||||
while (*(src + index) != '\0'){
|
||||
|
||||
//maj
|
||||
lettre = *(src + index);
|
||||
|
||||
//MAJ
|
||||
if (lettre > 64 && lettre < 91){
|
||||
if (lettre == 'Z') lettre = 'A';
|
||||
else lettre += 1;
|
||||
else lettre ++;
|
||||
}
|
||||
|
||||
//min
|
||||
else if (lettre > 97 && lettre < 124 ){
|
||||
|
||||
if (lettre == 'z')lettre = 'a';
|
||||
else lettre += 1;
|
||||
if (lettre > 96 && lettre < 124) {
|
||||
if (lettre == 'z') lettre = 'a';
|
||||
else lettre ++;
|
||||
}
|
||||
|
||||
*str = lettre;
|
||||
src ++;
|
||||
str ++;
|
||||
*(str + index) = lettre;
|
||||
index ++;
|
||||
}
|
||||
|
||||
*(str + index + 1) = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
printf("%s",my_weirddup("abb"));
|
||||
|
||||
}
|
||||
//TODO MARCHE MAIS À COMPLETER
|
||||
|
||||
int main(int args ,char **arg){
|
||||
|
||||
int index = 1;
|
||||
char *rslt = "";
|
||||
|
||||
while(index < args){
|
||||
rslt = my_weirddup(*(arg + index));
|
||||
printf("%s\n",rslt);
|
||||
free(rslt);
|
||||
index ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char *replace(char *str, char *sub){
|
||||
|
||||
//clc taille sub
|
||||
//nbr * x taille sub
|
||||
|
||||
int len_fin = 0;
|
||||
|
||||
//clc taille str
|
||||
int index = 0;
|
||||
int nb_etoile = 0;
|
||||
while( *(str + index)){
|
||||
if ( *(str + index) == '*') nb_etoile ++;
|
||||
|
||||
index ++;
|
||||
|
||||
}
|
||||
len_fin = index;
|
||||
|
||||
//clc taille sub
|
||||
index = 0;
|
||||
while (*(sub + index)) index ++;
|
||||
|
||||
//longueur finale
|
||||
len_fin += nb_etoile * index;
|
||||
|
||||
|
||||
char *rslt = malloc(len_fin);
|
||||
if (rslt == NULL) return NULL;
|
||||
|
||||
index = 0;
|
||||
int index_str = 0;
|
||||
int index_sub = 0;
|
||||
//parcours total
|
||||
while(*(str + index_str)){
|
||||
|
||||
index_sub = 0;
|
||||
//si le char est une etoile
|
||||
if (*(str + index_str) == '*'){
|
||||
//copie de sub dans rslt
|
||||
while(*(sub + index_sub)){
|
||||
*(rslt + index) = *(sub + index_sub);
|
||||
index_sub ++;
|
||||
index ++;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
*(rslt + index) = *(str + index_str);
|
||||
index ++;
|
||||
}
|
||||
index_str ++;
|
||||
|
||||
}
|
||||
|
||||
return rslt;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
int main(){
|
||||
|
||||
|
||||
char *test =replace("Hello *", "World!"); // Hello World!
|
||||
printf("%s\n", test);
|
||||
free(test);
|
||||
//printf("ici");
|
||||
test = replace("*H*e*l*l*o*", "BIM"); // BIMHBIMeBIMlBIMlBIMoBIM
|
||||
printf("%s\n", test);
|
||||
free(test);
|
||||
}*/
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,81 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int **trap_sweeper(char **mat, int rows, int cols){
|
||||
//Vraiment la merde les matrices
|
||||
int **mat_clc = malloc(rows * sizeof(int));
|
||||
if (mat_clc == NULL) { return NULL;}
|
||||
|
||||
// index, x, temp
|
||||
// le y = rows actuel
|
||||
int *values = calloc(5,sizeof(int));
|
||||
if (values == NULL) { free(mat_clc); return NULL;}
|
||||
//0 -> x
|
||||
//1 -> y
|
||||
//2 -> xt
|
||||
//3 -> yt
|
||||
//4 -> count
|
||||
|
||||
*(values + 1) = 0;
|
||||
|
||||
while (*(values + 1 ) < rows){
|
||||
|
||||
*(mat_clc + *(values + 1)) = calloc(cols, sizeof(int));
|
||||
*values = 0;
|
||||
|
||||
while(*values < cols){
|
||||
|
||||
if ( *( *(mat + *(values + 1)) + *values) == '#'){
|
||||
|
||||
*( *(mat_clc + *(values + 1)) + *values) = -1;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
*(values + 4) = 0;
|
||||
*(values + 3) = *(values + 1) - 1;
|
||||
|
||||
while (*(values + 3) <= *(values + 1) + 1){
|
||||
|
||||
*(values + 2) = *values - 1;
|
||||
while (*(values + 2) <= *values + 1){
|
||||
|
||||
if(*(values + 3) >= 0 && *(values + 3) < rows && *(values + 2) >= 0 && *(values + 2) < cols) {
|
||||
|
||||
if(*( *(mat + *(values + 3)) + *(values + 2)) == '#') (*(values + 4)) ++;
|
||||
}
|
||||
(*(values + 2)) ++;
|
||||
}
|
||||
(*(values + 3)) ++;
|
||||
}
|
||||
*(*(mat_clc + *(values + 1)) + *values) = *(values + 4);
|
||||
}
|
||||
(*values) ++;
|
||||
}
|
||||
(*(values + 1)) ++;
|
||||
}
|
||||
|
||||
return mat_clc;
|
||||
|
||||
}
|
||||
/*
|
||||
int main()
|
||||
{
|
||||
char *mat1[] = {
|
||||
"OOO#O", // 1 1 2 -1 2
|
||||
"#OO#O", //-1 3 4 -1 2
|
||||
"O##OO", // 2 -1 -1 3 2
|
||||
"OOOO#" // 1 2 2 2 -1
|
||||
};
|
||||
int **res = trap_sweeper(mat1, 4, 5);
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
for (int j = 0; j < 5; ++j)
|
||||
printf("%d ", res[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
free(res[i]);
|
||||
free(res);
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user