 # CAKP02 - Editorial

Chefs Special Palindrome

Author: Nitesh Dani

CAKEWALK

None

# PROBLEM:

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. Sentence-length palindromes ignore capitalization, special characters, and spaces.

Chef just studied about palindromes in his school and was amazed by the concept of palindrome but he does not likes palindromes having numbers.

Given a string s, your task is to identify whether it is a sentence-length palindrome that Chef likes.

# QUICK EXPLANATION:

First of all check whether the string contains any digits. If it does, the answer is "NO".

After that, simply loop through the string characters and if the character is alphabet, add it to a new string (change all characters to lower case).

Check if the newly created string is a palindrome.

# SOLUTION:

Setter's Solution
``````#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin >> t;
string s;
getline(cin, s);
while (t-- > 0)
{
getline(cin, s);
if (s.length() == 0)
cout << "YES" << endl;
else
{
bool flag = false;
for (int i = 0; i < s.length(); i++)
{
int d = s[i];
if (d >= 48 && d <= 57)
{
flag = true;
break;
}
}
if (flag) {
cout << "NO" << endl;
}
else {
bool flag1 = false;
transform(s.begin(), s.end(), s.begin(), ::tolower);
string h = "";

for (int i = 0; i < s.length(); i++)
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
h += s[i];

s = h;
reverse(h.begin(), h.end());
int v = s.compare(h);
if (v == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
}
}
``````
1 Like

The code was actually VERY SIMPLE with python. Literally easy. But of course you should be able to implement it properly. In my case I got 2-3 WA on this one because I didn’t read the special character thing!

Yes. We were hoping that people miss that thing. Quite sadistic but your devious plan succeeded either way…  