题意:对于输入的字符串,判断是否存在一个单词a=b+c
俩种方法,枚举每一个单词进行拼接,复杂度是n*n
枚举每一个单词,对单词进行substr,判断substr出来的是不在map里面
#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
constexpr int N = 120000;
string a[N];
map<string, int>strMaps;
void solve()
{
int n = 0;
while (cin >> a[n])
{
strMaps[a[n]] = 1;
n++;
}
for (int i=0;i<n;i++)
{
for (int j = 0;j < a[i].size();j++)
{
string str = a[i].substr(0,j+1);
if (strMaps[str] == 0)
continue;
str = a[i].substr(j+1);
if (strMaps[str] == 0)
continue;
cout << a[i] << endl;
break;
}
}
}
};
int main()
{
#ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve();
return 0;
}