Challenge: Palindrome Sentence

Lab C++ Beginner 10 points

Read a whole line. Ignoring spaces, punctuation and capital letters, is it a palindrome? Use two pointers that skip anything that isn't a letter or digit. Print yes or no.

Input

One line of text.

Output

yes or no.

Example

Input

A man, a plan, a canal: Panama

Output

yes
Sample input available Sample output available
Editor
C++

Hints

getline(cin, s) reads the whole line, spaces included.

isalnum() checks letters/digits; tolower() ignores case.

Solution explanation

One pass with two pointers: O(n) time, O(1) space.

Show solution
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    getline(cin, s);
    int l = 0, r = (int)s.size() - 1;
    bool ok = true;
    while (l < r) {
        if (!isalnum((unsigned char)s[l])) l++;
        else if (!isalnum((unsigned char)s[r])) r--;
        else if (tolower((unsigned char)s[l]) != tolower((unsigned char)s[r])) { ok = false; break; }
        else { l++; r--; }
    }
    cout << (ok ? "yes" : "no") << endl;
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD