text: Pairs of complete strings in two sets of strings | C ++ implementation for find pairs of complete strings . ; Returns count of complete pairs from set [ 0. . n - 1 ] and set2 [ 0. . m - 1 ] ; Consider all pairs of both strings ; Create a concatenation of current pair ; Compute frequencies of all characters in the concatenated string . ; If frequency of any character is not greater than 0 , then this pair is not complete . ; Driver code
code: #include <iostream> NEW_LINE using namespace std ; int countCompletePairs ( string set1 [ ] , string set2 [ ] , int n , int m ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { string concat = set1 [ i ] + set2 [ j ] ; int frequency [ 26 ] = { 0 } ; for ( int k = 0 ; k < concat . length ( ) ; k ++ ) frequency [ concat [ k ] - ' a ' ] ++ ; int i ; for ( i = 0 ; i < 26 ; i ++ ) if ( frequency [ i ] < 1 ) break ; if ( i == 26 ) result ++ ; } } return result ; } int main ( ) { string set1 [ ] = { " abcdefgh " , " geeksforgeeks " , " lmnopqrst " , " abc " } ; string set2 [ ] = { " ijklmnopqrstuvwxyz " , " abcdefghijklmnopqrstuvwxyz " , " defghijklmnopqrstuvwxyz " } ; int n = sizeof ( set1 ) / sizeof ( set1 [ 0 ] ) ; int m = sizeof ( set2 ) / sizeof ( set2 [ 0 ] ) ; cout << countCompletePairs ( set1 , set2 , n , m ) ; return 0 ; }