Identifying related words with the use of Wildcards in c++ -


ok, i've been trying come solution problem. problem is: given list of 3 letter words (size of list irrelevant think), how can identify words in list differ first word in list @ 1 letter. have word pat identify words in list are:

pa_ such pay p_t such pot _ot such rot

is there way implement wildcards in c++?

[this may more complex assignment requires avoids slow string comparisons , regular expressions]

given 3-letter word, might consider representing each word 4-byte integer. example, in "pat" letter 'p' 0x70 (ascii), 'a' 0x61 , 't' 0x74 represent "pat" integer 0x706174. likewise 3-letter words in test list.

next, combination of tests required 2 of 3 letters match (in same order) is:

  • p?t test 0x70??74
  • ?at test 0x??6174
  • pa? test 0x7061??

ps can add stackoverflow 'code sample' button suppose reformat selection code weird in firefox. 1-minute post has taken 20 minutes format!

// assume array words[] of strings int word0 = calc_int_from_word(words[0]);  (int ii = 1; ii < words.count; ii++) {   int wordii = calc_int_from_word(words[ii]);    if (wordii & 0xffff00 == word0 & 0xffff00 ||       wordii & 0xff00ff == word0 & 0xff00ff ||       wordii & 0x00ffff == word0 & 0x00ffff)   {     // words[ii] matches words[0] in @ least 2 letters   } } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -