题目链接如下:
代码如下:
cpp
#include <iostream>
#include <string>
#include <vector>
#include <set>
// #define debug
int main(){
#ifdef debug
freopen("0.txt", "r", stdin);
freopen("1.txt", "w", stdout);
#endif
std::string word;
std::vector<std::string> vec;
std::set<std::string> st;
while (std::cin >> word){
vec.push_back(word);
st.insert(word);
}
for (int i = 0; i < vec.size(); ++i){
for (int j = 1; j < vec[i].size(); ++j){
if(st.count(vec[i].substr(0, j)) && st.count(vec[i].substr(j))){
std::cout << vec[i] << std::endl;
break;
}
}
}
#ifdef debug
fclose(stdin);
fclose(stdout);
#endif
return 0;
}