#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
//#include "ChenHC.h"
#define CLOSE() ios::sync_with_stdio(false)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
const int maxn = 1e5 + 5;
using LL = long long;
using UI = unsigned int;
using namespace std;
//------------------------------------------------------------------------------------------//
//直接组合超时,改用拆分的思想就能过。
set<string> word;
int main() {
string s;
while (cin >> s) word.insert(s);
int beg = 0;
string s1, s2;
for (auto i = word.begin(); i != word.end(); ++i) {
for (int j = 0; j < (*i).size(); j++) {
s1 = (*i).substr(0, j + 1);
s2 = (*i).substr(j + 1);
if (word.count(s1) && word.count(s2)) {
cout << *i << endl;
break;
}
}
}
return 0;
}
习题5-5 复合词(Compound Words, UVa 10391)
最新推荐文章于 2023-02-01 10:53:19 发布