class Solution {
public:
bool areSentencesSimilar(string s1, string s2) {
if(s1.size() < s2.size()) return areSentencesSimilar(s2,s1);
//如果a串的前缀和后缀与b相同的长度比b串长,那么就合法
//因为只要插中间那一段
stringstream ssni1(s1),ssni2(s2); //可以读入单词
string s;
vector<string> a,b;
while(ssni1 >> s){
a.push_back(s);
}
cout << endl;
while(ssni2 >> s){
b.push_back(s);
}
int pre = 0; //前缀的长度
for(int i = 0,j = 0;i < b.size();++i,++j){
if(a[j] == b[i]) pre++;
else break;
}
int out = 0;
for(int i = b.size() - 1,j = a.size() - 1;i >= 0;--i,--j){
if(a[j] == b[i]) out++;
else break;
}
if(pre + out >= b.size()) return true;
return false;
}
};