From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/piscine/palindrome/palindrome.c | 47 ++++++++++++++++++++++++++++++++++ graphs/piscine/palindrome/palindrome.h | 6 +++++ 2 files changed, 53 insertions(+) create mode 100644 graphs/piscine/palindrome/palindrome.c create mode 100644 graphs/piscine/palindrome/palindrome.h (limited to 'graphs/piscine/palindrome') diff --git a/graphs/piscine/palindrome/palindrome.c b/graphs/piscine/palindrome/palindrome.c new file mode 100644 index 0000000..2ecacfd --- /dev/null +++ b/graphs/piscine/palindrome/palindrome.c @@ -0,0 +1,47 @@ +#include "palindrome.h" + +#include + +int palindrome(const char *s) +{ + if (s == NULL) + { + return 0; + } + + if (*s == '\0') + { + return 1; + } + + const char *p = s; + while (*p) + { + p++; + } + p--; + + while (p > s) + { + while ((*p < '0' || (*p > '9' && *p < 'A') || (*p > 'Z' && *p < 'a') + || *p > 'z') + && p > s) + { + p--; + } + while ((*s < '0' || (*s > '9' && *s < 'A') || (*s > 'Z' && *s < 'a') + || *s > 'z') + && p > s) + { + s++; + } + if (*p != *s) + { + return 0; + } + p--; + s++; + } + + return 1; +} diff --git a/graphs/piscine/palindrome/palindrome.h b/graphs/piscine/palindrome/palindrome.h new file mode 100644 index 0000000..8595911 --- /dev/null +++ b/graphs/piscine/palindrome/palindrome.h @@ -0,0 +1,6 @@ +#ifndef PALINDROME_H +#define PALINDROME_H + +int palindrome(const char *s); + +#endif /* !PALINDROME_H */ -- cgit v1.2.3