Check if expression contains redundant bracket or not | Set 2 | C ++ program to check for / redundant braces in the string ; Function to check for redundant braces ; count of no of signs ; Driver function
#include <iostream> NEW_LINE using namespace std ; bool IsRedundantBraces ( string A ) { int a = 0 , b = 0 ; for ( int i = 0 ; i < A . size ( ) ; i ++ ) { if ( A [ i ] == ' ( ' && A [ i + 2 ] == ' ) ' ) return 1 ; if ( A [ i ] == ' * ' A [ i ] == ' + ' A [ i ] == ' - ' A [ i ] == ' / ' ) a ++ ; if ( A [ i ] == ' ( ' ) b ++ ; } if ( b > a ) return 1 ; return 0 ; } int main ( ) { string A = " ( ( ( a + b ) ▁ + ▁ c ) ▁ + ▁ d ) " ; if ( IsRedundantBraces ( A ) ) { cout << " YES STRNEWLINE " ; } else { cout << " NO " ; } }