For each lowercase English alphabet find the count of strings having these alphabets | C ++ program to find count of strings for each letter [ a - z ] in english alphabet ; Function to find the countStrings for each letter [ a - z ] ; Initialize result as zero ; Mark all letter as not visited ; Loop through each strings ; Increment the global counter for current character of string ; Instead of re - initialising boolean vector every time we just reset all visited letter to false ; Print count for each letter ; Driver program ; Given array of strings ; Call the countStrings function
#include <bits/stdc++.h> NEW_LINE using namespace std ; void CountStrings ( vector < string > & str ) { int size = str . size ( ) ; vector < int > count ( 26 , 0 ) ; vector < bool > visited ( 26 , false ) ; for ( int i = 0 ; i < size ; ++ i ) { for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { if ( visited [ str [ i ] [ j ] ] == false ) count [ str [ i ] [ j ] - ' a ' ] ++ ; visited [ str [ i ] [ j ] ] = true ; } for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { visited [ str [ i ] [ j ] ] = false ; } } for ( int i = 0 ; i < 26 ; ++ i ) { cout << count [ i ] << " ▁ " ; } } int main ( ) { vector < string > str = { " i " , " will " , " practice " , " everyday " } ; CountStrings ( str ) ; return 0 ; }