Programming Pearl -- Modified words

Source: Internet
Author: User

The following two paragraphs are taken from programming Pearl River:

Give an English dictionary to find a set of all the modified words. For example, "pots", "stop", and "tops" are different words, because each word can be obtained by changing the order of letters in other words.

What we got, "Aha! The Brainwave "identifies every word in the dictionary, so that words in the same modified word class have the same identifier. Then, all words with the same logo are combined. This simplifies the problem of original modified words into two subproblems: Selecting the words with the same logo and the words with the same logo in the set.For the first question, we can use a sort-based identifier: to sort the letters in a word in alphabetical order. To solve the second problem, we arrange all words in the order of their identifiers.


 # pragma warning (Disable: 4786) # include 
  
    # include 
    # include 
    
      # include 
     
       using namespace STD; int compare_string (const void * a, const void * B) {return * (char *) (a)-* (char *) (B);} void findanagram (char * file_name) {ifstream in_file (file_name ); string word_sort; string word; multimap 
      
        word_map; while (in_file> word) {word_sort = word; qsort (Word_sort.begin (), word_sort.length (), sizeof (char), compare_string); word_map.insert (make_pair (word_sort, word);} multimap 
       
         :: const_iterator iter = word_map.begin (); multimap 
        
         :const_iterator iter_end = word_map.end (); While (iter_end! = ITER) {cout 
         
           first <":" 
          
            second 
           
          
         
        
       
      
     
    
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.