zoukankan      html  css  js  c++  java
  • 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 theconcatenation 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 should contain all the compound words, one per line, inalphabetical order.

    Sample Input

    a
    alien
    born
    less
    lien
    never
    nevertheless
    new
    newborn
    the
    zebra
    

    Sample Output

    alien
    newborn


    AC代码:
    #include"iostream"
    #include"set"
    using namespace std;
    int main()
    {
        set<string> dic;
        string s;
        while(cin>>s) dic.insert(s);
        set<string> ::iterator it;
        for(it=dic.begin();it!=dic.end();it++)
        {
         string str,sub1,sub2;
         str=*it;
         for(int i=0;i<str.size()-1;i++)
         {
             sub1=str.substr(0,i+1);
             sub2=str.substr(i+1,str.size()-i-1);
             if(dic.find(sub1)!=dic.end()&&dic.find(sub2)!=dic.end())
             {
                cout<<str<<endl;
                break;     //一定要即时break掉,以免重复
             }
         }
    
    
        }
        return 0;
    }
  • 相关阅读:
    工作中的几个问题
    linux初学之二
    VMWARE虚拟机卡死
    记昨天、今天的部分工作内容及问题
    linux初学之一
    今日阅读项目源码
    python POST XML
    python的超简单WEB服务器
    在notepad++中运行python
    安装python图形库:Matplotlib
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4659949.html
Copyright © 2011-2022 走看看