UVA 10391(p135)----Compound Words

#include<set>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define debu
using namespace std;
set<string> s;
int main()
{
#ifdef debug
    freopen("in.in","r",stdin);
#endif
    string st;
    while(cin>>st) s.insert(st);
    set<string>::iterator it=s.begin();
    for(it; it!=s.end(); it++)
    {
        string tmp=*it;
        int l=tmp.length();
        for(int j=0; j<l; j++)
        {
            if(s.count(tmp.substr(0,j+1))&&s.count(tmp.substr(j+1,l-j-1)))
            {
                cout<<tmp<<endl;
                break;
            }
        }
    }
    return 0;
}

你可能感兴趣的:(UVA 10391(p135)----Compound Words)