Find all strings that match specific pattern in a dictionary | C # program to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; For each word in the dictionary ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static bool check ( string pattern , string word ) { if ( pattern . Length != word . Length ) return false ; int [ ] ch = new int [ 128 ] ; int Len = word . Length ; for ( int i = 0 ; i < Len ; i ++ ) { if ( ch [ ( int ) pattern [ i ] ] == 0 ) { ch [ ( int ) pattern [ i ] ] = word [ i ] ; } else if ( ch [ ( int ) pattern [ i ] ] != word [ i ] ) { return false ; } } return true ; } static void findMatchedWords ( HashSet < string > dict , string pattern ) { int Len = pattern . Length ; string result = " ▁ " ; foreach ( string word in dict ) { if ( check ( pattern , word ) ) { result = word + " ▁ " + result ; } } Console . Write ( result ) ; } static void Main ( ) { HashSet < string > dict = new HashSet < string > ( new string [ ] { " abb " , " abc " , " xyz " , " xyy " } ) ; string pattern = " foo " ; findMatchedWords ( dict , pattern ) ; } }