Check if all the palindromic sub | C ++ implementation of the approach # include < bitsstdc ++ . h > ; Function to check if the string is palindrome ; Function that checks whether all the palindromic sub - strings are of odd length . ; Creating each substring ; If the sub - string is of even length and is a palindrome then , we return False ; Driver code
using namespace std ; bool checkPalindrome ( string s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s [ i ] != s [ s . length ( ) - i - 1 ] ) return false ; } return true ; } bool CheckOdd ( string s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { string x = " " ; for ( int j = i ; j < n ; j ++ ) { x += s [ j ] ; if ( x . length ( ) % 2 == 0 && checkPalindrome ( x ) == true ) return false ; } } return true ; } int main ( ) { string s = " geeksforgeeks " ; if ( CheckOdd ( s ) ) cout << ( " YES " ) ; else cout << ( " NO " ) ; }