diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/piscine/palindrome | |
add: graphs et rushs
Diffstat (limited to 'graphs/piscine/palindrome')
| -rw-r--r-- | graphs/piscine/palindrome/palindrome.c | 47 | ||||
| -rw-r--r-- | graphs/piscine/palindrome/palindrome.h | 6 |
2 files changed, 53 insertions, 0 deletions
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 <stddef.h> + +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 */ |
