原题链接:https://vjudge.net/problem/UVA-10391
分类:<string>
备注:水题
代码如下:
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main(void)
{
string s;
set<string>word;
while (cin >> s)word.insert(s);
for (set<string>::iterator it = word.begin(); it != word.end(); ++it)
{
int len = (*it).length();
string a, b;
for (int j = 1; j <= len - 1; j++)
{
a.assign(*it, 0, j);
b.assign(*it, j, len - j);
if (word.count(a) && word.count(b))
{
cout << *it << "\n";
break;
}
}
}
return 0;
}