C++编写,使用了string类的find方法
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s = "deletealgorihm";
string t = "lgh";
int len = t.size();
int count = 0;
int loc = s.find(t[count++]);
cout << "#" << t[count-1] << " location:" << loc+1 << endl;
while (loc != string::npos)
{
if (s.find(t[count], loc + 1)==string::npos)
break;
if (count < len)
{
loc = s.find(t[count++],loc+1);
cout << "#" << t[count-1] << " location:" << loc+1 << endl;
}
else
break;
}
if (count == len)
cout << "可以得到!";
else
cout << "无法得到!";
}