[Binary Search] Compound Words uva10391

Source: Internet
Author: User

Problem E: Compound Words

You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.

Input

Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 120,000 words.

Output

Your output shoshould contain all the compound words, one per line, in alphabetical order.

Sample Input
aalienbornlesslienneverneverthelessnewnewbornthezebra

Sample Output
aliennewborn

Question: give a series of words and find out the words composed of two words. Sort them directly and search for them in binary mode.

#include
 
  #include
  
   #includeusing namespace std;int k;string st[120005];bool cmp(string x,string y){    return x
   
    str)        {            right=mid-1;        }        else return 1;    }    return 0;}int main(){    string str;    int i,j;    k=0;    while(getline(cin,str))    {        st[k++]=str;    }    sort(st,st+k,cmp);    //cout<
    
     

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.