问题描述
p10391原题链接:UVaOJ 10391 - Compound Words
相关说明:本题为《算法竞赛入门经典(第2版)》习题 5-5
解法一:集合+字符串子串
水题,直接用集合存储,扫描出每个符合条件的字符串即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <bits/stdc++.h> using namespace std; int main() { string s; set<string> words; while (cin >> s) words.insert(s); for (auto &word: words) for (int i = 0; i < word.size(); i++) if (words.count(word.substr(0, i)) && words.count(word.substr(i))) { cout << word << endl; break; } return 0; } |
1 |
#TODO |