zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【习题5-5 UVA-10391】Compound Words

习题 UVa words
2023-09-14 09:03:45 时间

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

枚举每一个串的分割点。 看看左右两个串在不在字符串中即可。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int N = 12e4;
string s;
vector <string> v;
map<string, int> mmap;

int main()
{
	//freopen("F:\\rush.txt", "r", stdin);
	ios::sync_with_stdio(0), cin.tie(0);
	while (cin >> s) v.push_back(s),mmap[s] = 1;
	sort(v.begin(), v.end());
	int n = v.size();
	for (int i = 0; i < n; i++)
	{
		int len = v[i].size();
		for (int j = 0; j < len-1; j++)
		{
			string s1 = v[i].substr(0, j + 1), s2 = v[i].substr(j + 1);
			if (mmap[s1] && mmap[s2])
			{
				cout << v[i] << endl;
				break;
			}
		}
	}
	return 0;
}