CodeForces - 501B Misha and Changing Handles
题意:给定一些字符串,其中的字符串,可以由其它两个字符串拼接得到,则输出这个字符串。
直接暴力分解每一个字符串,然后find()寻找一下set是否有存在的字符串,匹配成功输出即可。
#include<iostream>
#include<set>
using namespace std;
set<string>x;
bool judge(string word)
{
for(int i=1;i<word.size();i++)
if(x.find(word.substr(0,i))!=x.end())
if(x.find(word.substr(i))!=x.end())
return 1;
return 0;
}
int main()
{
string word;
while(getline(cin,word))
{
if(word.size()==0) break;
x.insert(word);
}
for(auto it:x)
{
if(judge(it))
cout<<it<<endl;
}
return 0;
}