UVa 10391 - Compound Words

来源:互联网 发布:广电总局的网络 编辑:程序博客网 时间:2024/04/27 16:58

10391 - Compound Words


思路:用set储存,之后每个词分成两部分寻找是否有这两个单词(hash)。


#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <sstream>#include <cmath>#include <algorithm>#include <vector>#include <iomanip>#include <map>#include <set>using namespace std;int main() {set<string> ss;string str;while (cin >> str) {ss.insert(str);}for (set<string>::iterator iter = ss.begin(); iter != ss.end(); iter++) {string t = *iter;int len = t.size();for (int i = 0; i < len; i++) {string a = t.substr(0, i + 1);string b = t.substr(i + 1, len - i);if (ss.find(a) != ss.end() && ss.find(b) != ss.end()) {cout << t << endl;break;}}}return 0;}


0 0
原创粉丝点击