include [HTML_REMOVED]
using namespace std;
int main()
{
string s, a, b;
char c;
while (cin >> c, c != ‘,’) s += c;
while (cin >> c, c != ‘,’) a += c;
while (cin >> c) b += c;
int m = -1, n = -1;
string s1, s2;
for (int i = 0 ; i < s.size(); i ++)
{
if (s[i] == a[0])
{
s1 = s.substr(i, a.size());
if (s1 == a)
{
m = i;
break;
}
else continue;
}
else continue;
}
for (int i = s.size(); i ; i --)
{
if(s[i] == b[0])
{
s2 = s.substr(i, b.size() );
if (s2 == b)
{
n = i;
break;
}
else continue;
}
else continue;
}
if (m + a.size() - 1 >= n || m == -1 || n == -1) cout << "-1";
else cout << n - (m + a.size() - 1) - 1;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla