#include
#include
using namespace std;
int main()
{
char s[255],t[255];
cin.getline(s,255);
cin.getline(t,255);
int slen = strlen(s) , tlen = strlen(t);
int i = 0;
bool flag = false;
for(int j=0 ; j<slen ; j++)
{
if(s[j] == t[i])
i++;
if(i==tlen)
{
flag = true;
break;
}
}
if(flag==true)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}
你的for循环查找子字符串的算法是错的,你的算法是,判断子字符串的每一个字符是不是依次在字符串中。例如:判断abc是否包含ac,用你的逻辑就会判断为yes.