Count of Reverse Bitonic Substrings in a given String | C ++ Program to implement the above approach ; Function to calculate the number of reverse bitonic substrings ; Stores the count ; All possible lengths of substrings ; Starting point of a substring ; Ending point of a substring ; Condition for reverse bitonic substrings of length 1 ; Check for decreasing sequence ; If end of substring is reached ; For increasing sequence ; If end of substring is reached ; Return the number of bitonic substrings ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int CountsubString ( char str [ ] , int n ) { int c = 0 ; for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; char temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } int k = i + 1 ; while ( temp > str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp < str [ k ] && k <= j && f != 2 ) { temp = str [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } return c ; } int main ( ) { char str [ ] = " bade " ; cout << CountsubString ( str , strlen ( str ) ) ; return 0 ; }