Palindrome Sentence
Completed
Read a line and print YES if it is a palindrome ignoring case and non-letters, else NO.
Input
One line.
Output
YES or NO
Example
Input
A man, a plan, a canal: Panama
Output
YES
Editor
C
Hints
Skip characters that aren't letters from both ends.
Solution explanation
Skipping inside the two-pointer loop avoids building a cleaned copy.
Show solution
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char s[200];
fgets(s, 200, stdin);
int i = 0, j = strlen(s) - 1, ok = 1;
while (i < j) {
if (!isalpha(s[i])) { i++; continue; }
if (!isalpha(s[j])) { j--; continue; }
if (tolower(s[i]) != tolower(s[j])) { ok = 0; break; }
i++;
j--;
}
printf(ok ? "YES\n" : "NO\n");
return 0;
}