#include #include #include #include using namespace std; struct datum { string combination; unsigned long present; }; unsigned long present( string s ) { int j; unsigned long present = 0; for( j = 0; j < s.length(); j++ ) { if( s[j] >= 'A' && s[j] <= 'Z' ) s[j] += 'a' - 'A'; if( s[j] < 'a' || s[j] > 'z' ) continue; present |= 1 << (s[j] - 'a'); } return present; } int main( ) { int i; ifstream in( "digest.txt" ); vector data; // Read combinations from digest string line; for( i = 0; getline( in, line ); i++ ) { datum d = { line, present( line ) }; data.push_back( d ); } // Answer queries while( getline( cin, line ) ) { unsigned long query = present( line ); for( i = 0; i < data.size(); i++ ) { if( (query & ~data[i].present) == 0 ) break; } cout << data[i].combination << endl; } return 0; }