Minimum number of basic logic gates required to realize given Boolean expression | C ++ implementation of the above approach ; Function to count the total number of gates required to realize the boolean expression S ; Length of the string ; Stores the count of total gates ; Traverse the string ; AND , OR and NOT Gate ; Print the count of gates required ; Driver Code ; Input ; Function call to count the total number of gates required
#include <bits/stdc++.h> NEW_LINE using namespace std ; void numberOfGates ( string s ) { int N = s . size ( ) ; int ans = 0 ; for ( int i = 0 ; i < ( int ) s . size ( ) ; i ++ ) { if ( s [ i ] == ' . ' s [ i ] == ' + ' s [ i ] == '1' ) { ans ++ ; } } cout << ans ; } int main ( ) { string S = " ( 1 - A ) . B + C " ; numberOfGates ( S ) ; }