Print list items containing all characters of a given word | C # program to print all strings that contain all characters of a word ; Prints list items having all characters of word ; Since calloc is used , map [ ] is initialized as 0 ; Set the values in map ; Get the length ( ) of given word ; Check each item of list if has all characters of word ; unset the bit so that strings like sss not printed ; Set the values in map for next item ; Driver code
using System ; class GFG { static int NO_OF_CHARS = 256 ; static void print ( string [ ] list , string word , int list_size ) { int [ ] map = new int [ NO_OF_CHARS ] ; int i , j , count , word_size ; for ( i = 0 ; i < word . Length ; i ++ ) map [ word [ i ] ] = 1 ; word_size = word . Length ; for ( i = 0 ; i < list_size ; i ++ ) { for ( j = 0 , count = 0 ; j < list [ i ] . Length ; j ++ ) { if ( map [ list [ i ] [ j ] ] > 0 ) { count ++ ; map [ list [ i ] [ j ] ] = 0 ; } } if ( count == word_size ) Console . WriteLine ( list [ i ] ) ; for ( j = 0 ; j < word . Length ; j ++ ) map [ word [ j ] ] = 1 ; } } public static void Main ( string [ ] args ) { string str = " sun " ; string [ ] list = { " geeksforgeeks " , " unsorted " , " sunday " , " just " , " sss " } ; print ( list , str , 5 ) ; } }