问题:给定字符串s和t,判断从t中删除0或多个字符,是否直接得到串s:
思路:以s为标杆,从t中按顺序查找每个字符
流程:①读取s和t
②对s中每一个字符,从t[0]开始找;找到后从此位置继续查找后一个字符;
③如果最后都找到了,输出yes,否则输出no
#include<iostream>
#include<string>
using namespace std;
int main()
{
#ifndef UVa
FILE* fp;
freopen_s(&fp, "data.in.txt", "r", stdin);
freopen_s(&fp, "data.out.txt", "w", stdout);
#endif
string s, t;
while (cin >> s >> t) {
bool bget = true;
string::size_type pos = -1;
for (string::iterator iter = s.begin(); iter != s.end(); ++iter) {
pos = t.find(*iter, pos+1);
if (pos == string::npos) {
bget = false;
break;
}//endif
}//endfor
if (bget == false)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}