text: Count of strings that does not contain Arc intersection | C ++ program for the above approach ; Function to check if there is arc intersection or not ; Traverse the string S ; Insert all the elements in the stack one by one ; Extract the top element ; Pop out the top element ; Check if the top element is same as the popped element ; Otherwise ; If the stack is empty ; Function to check if there is arc intersection or not for the given array of strings ; Stores count of string not having arc intersection ; Iterate through array ; Length of every string ; Function Call ; Print the desired count ; Driver Code ; Function Call
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int arcIntersection ( string S , int len ) { stack < char > stk ; for ( int i = 0 ; i < len ; i ++ ) { stk . push ( S [ i ] ) ; if ( stk . size ( ) >= 2 ) { char temp = stk . top ( ) ; stk . pop ( ) ; if ( stk . top ( ) == temp ) { stk . pop ( ) ; } else { stk . push ( temp ) ; } } } if ( stk . empty ( ) ) return 1 ; return 0 ; } void countString ( string arr [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int len = arr [ i ] . length ( ) ; count += arcIntersection ( arr [ i ] , len ) ; } cout << count << endl ; } int main ( ) { string arr [ ] = { "0101" , "0011" , "0110" } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countString ( arr , N ) ; return 0 ; }