10391:Compound Words

Compound Words

我的思路:对于每个单词,依次枚举其所有可能组合的情况,看其两个子单词是否存在于dict中。

version 1(30ms):

#include<cstdio>
#include<iostream>
#include<set>
#include<cstring>
using namespace std;
int main(){
    string w;
    set<string>dict;
    while(cin>>w) dict.insert(w);
    set<string>::iterator i;
    for(i = dict.begin();i != dict.end();i++){
        int j = 1;
        for(;j < (*i).length();j++){
            if(dict.count((*i).substr(0,j)) && dict.count((*i).substr(j))) break;
        }
        if(j < (*i).length()) cout<<*i<<endl;
    }
    return 0;
}

posted @ 2018-04-22 21:18  ACLJW  阅读(202)  评论(0编辑  收藏  举报