CamelCase Pattern Matching | C ++ to find CamelCase Pattern matching ; Function that prints the camel case pattern matching ; Map to store the hashing of each words with every uppercase letter found ; Traverse the words array that contains all the string ; Initialise str as empty ; length of string words [ i ] ; For every uppercase letter found map that uppercase to original words ; Traverse the map for pattern matching ; If pattern matches then print the corresponding mapped words ; If word not found print " No ▁ match ▁ found " ; Driver 's Code ; Pattern to be found ; Function call to find the words that match to the given pattern
#include " bits / stdc + + . h " NEW_LINE using namespace std ; void CamelCase ( vector < string > & words , string pattern ) { map < string , vector < string > > map ; for ( int i = 0 ; i < words . size ( ) ; i ++ ) { string str = " " ; int l = words [ i ] . length ( ) ; for ( int j = 0 ; j < l ; j ++ ) { if ( words [ i ] [ j ] >= ' A ' && words [ i ] [ j ] <= ' Z ' ) { str += words [ i ] [ j ] ; map [ str ] . push_back ( words [ i ] ) ; } } } bool wordFound = false ; for ( auto & it : map ) { if ( it . first == pattern ) { wordFound = true ; for ( auto & itt : it . second ) { cout << itt << endl ; } } } if ( ! wordFound ) { cout << " No ▁ match ▁ found " ; } } int main ( ) { vector < string > words = { " Hi " , " Hello " , " HelloWorld " , " HiTech " , " HiGeek " , " HiTechWorld " , " HiTechCity " , " HiTechLab " } ; string pattern = " HT " ; CamelCase ( words , pattern ) ; return 0 ; }