Number of strings which starts and ends with same character after rotations | C ++ program for the above approach ; Function to find the count of string with equal end after rotations ; To store the final count ; Traverse the string ; If current character is same as the previous character then increment the count ; Return the final count ; Driver Code ; Given string ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countStrings ( string s ) { int cnt = 0 ; for ( int i = 1 ; s [ i ] ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { cnt ++ ; } } return cnt ; } int main ( ) { string str ( " aacbb " ) ; cout << countStrings ( str ) ; return 0 ; }