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;
}

相关文章:

  • 2021-12-29
  • 2021-12-05
  • 2021-06-13
  • 2021-07-09
  • 2021-09-21
  • 2021-08-14
  • 2021-09-29
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-07-29
相关资源
相似解决方案