text: Check if a string can be split into even length palindromic substrings | C ++ program for the above approach ; Function to check string str can be split a string into even length palindromic substrings ; Initialize a stack ; Iterate the string ; If the i - th character is same as that at the top of the stack then pop the top element ; Else push the current charactor into the stack ; If the stack is empty , then even palindromic substrings are possible ; Else not - possible ; Driver Code ; Given string ; Function Call
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string s , int n ) { stack < char > st ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! st . empty ( ) && st . top ( ) == s [ i ] ) st . pop ( ) ; else st . push ( s [ i ] ) ; } if ( st . empty ( ) ) { return true ; } else { return false ; } } int main ( ) { string str = " aanncddc " ; int n = str . length ( ) ; if ( check ( str , n ) ) { cout << " Yes " << endl ; } else { cout << " No " << endl ; } return 0 ; }