心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
是题目没有说清楚,还是我E文不够好?一开始以为组成一个单词的两个部分不能相同,后来删除这个检测之后AC了。
很简单,枚举每个单词分成哪两个部分,看着两个单词在不在字典中。
具体做法,使用STL中的set即可。
以下是我的代码:
#include<iostream>
#include
<string>
#include
<vector>
#include
<set>
#include
<algorithm>
#include
<cstdio>
using namespace std;

int main()
{
    
/*
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    //
*/
    
    
set<string> words_set;
    
string s;
    
while(cin>>s)
        words_set.insert(s);
    
    vector
<string> ans;
    
for(set<string>::const_iterator i=words_set.begin();i!=words_set.end();i++)
    {
        
string t(*i);
        
for(int pos=1;pos<t.size();pos++)
        {
            
string part1(t.begin(),t.begin()+pos);
            
if(!words_set.count(part1))
                
continue;
            
string part2(t.begin()+pos,t.end());
            
if(!words_set.count(part2))
                
continue;
            ans.push_back(t);
            
break;
        }
    }
    sort(ans.begin(),ans.end());
    
    
for(vector<string>::const_iterator i=ans.begin();i!=ans.end();i++)
        cout
<<*i<<endl;
    
return 0;
}
posted on 2011-03-06 19:13 lee1r 阅读(469) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:数据结构

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理