Count substrings of a given string whose anagram is a palindrome | C ++ program for the above approach ; Function to print count of substrings whose anagrams are palindromic ; Stores the answer ; Iterate over the string ; Set the current character ; Parity update ; Print the final count ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countSubstring ( string s ) { int res = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int x = 0 ; for ( int j = i ; j < s . length ( ) ; j ++ ) { int temp = 1 << s [ j ] - ' a ' ; x ^= temp ; if ( ( x & ( x - 1 ) ) == 0 ) res ++ ; } } cout << res ; } int main ( ) { string str = " aaa " ; countSubstring ( str ) ; return 0 ; }