Allow for palindromes with non-alpha characters
This commit is contained in:
parent
348f5d76e5
commit
ad0a18e8a9
|
@ -1,8 +1,18 @@
|
||||||
int palindrome(const char *str, unsigned len) {
|
#include <ctype.h>
|
||||||
unsigned idx = 0;
|
|
||||||
|
|
||||||
for(; idx < (len - (len % 2)) / 2; idx += 1) {
|
int palindrome(const char *str, unsigned len) {
|
||||||
if(str[idx] != str[len - idx - 1]) {
|
const char *start = str;
|
||||||
|
const char *end = str + len - 1;
|
||||||
|
|
||||||
|
while(start < end) {
|
||||||
|
if(!isalpha(*start)) {
|
||||||
|
start += 1;
|
||||||
|
} else if(!isalpha(*end)) {
|
||||||
|
end -= 1;
|
||||||
|
} else if(tolower(*start) == tolower(*end)) {
|
||||||
|
start += 1;
|
||||||
|
end -= 1;
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue