Compound Words UVA

来源:互联网 发布:什么软件测试兼容性 编辑:程序博客网 时间:2024/06/06 08:44

问题类型:STL-Map。

03pie’s solution for [UVA-10391]
题目链接

#include<iostream>#include<cstring>#include<map>using namespace std;map<string,int> words;int main(){    //freopen("F://inp.txt","r",stdin);    string word;    while(cin>>word){        words[word]=word.size();    }    for(map<string,int>::iterator it=words.begin();it!=words.end();++it){        int len=it->second;        string a=it->first,left,right;        if(len>1){            for(int i=1;i<len;i++){                string left=a.substr(0,i);                 string right=a.substr(i,len-i);                if(words[left]&&words[right]){                    cout<<a<<"\n";                    break;                }            }               }    }    return 0;}
0 0