Check given string is oddly palindrome or not | C ++ program for the above approach ; Function to check if the string str is palindromic or not ; Iterate the string str from left and right pointers ; Keep comparing characters while they are same ; If they are not same then return false ; Return true if the string is palindromic ; Function to make string using odd indices of string str ; Functions checks if characters at odd index of the string forms palindrome or not ; Make odd indexed string ; Check for Palindrome ; Driver Code ; Given string ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPalindrome ( string str ) { int l = 0 ; int h = str . size ( ) - 1 ; while ( h > l ) { if ( str [ l ++ ] != str [ h -- ] ) { return false ; } } return true ; } string makeOddString ( string str ) { string odd = " " ; for ( int i = 1 ; i < str . size ( ) ; i += 2 ) { odd += str [ i ] ; } return odd ; } void checkOddlyPalindrome ( string str ) { string odd = makeOddString ( str ) ; if ( isPalindrome ( odd ) ) cout << " Yes " << endl ; else cout << " No " << endl ; } int main ( ) { string str = " ddwfefwde " ; checkOddlyPalindrome ( str ) ; return 0 ; }