这道题目真的很水欸,还以为越来越难╮(╯▽╰)╭
题目
输入两个字符串s和t,判断是否可以从t中删除0个或者多个字符(其他字符顺序不变),得到字符串t。
样例输入
abcde bce
abcd bc
样例输出
no
yes
代码如下:(:з)∠)
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
string s,t;
int main()
{
while(cin>>s>>t)
{
int l1,l2,counts=0;
l1=s.length();
l2=t.length();
for(int i=0;i<l1;i++)
{
if(s[i]==t[counts])
counts++;
}
if(counts==l2)//只需最后判断满足的与t字符串长度比较~
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}
本文深入探讨了一种简单的字符串匹配算法,通过从一个较长的字符串中查找是否包含另一个字符串的所有字符,且保持原有顺序不变。文章提供了详细的代码实现,并通过实例展示了如何判断一个字符串是否为另一个字符串的子序列。
259

被折叠的 条评论
为什么被折叠?



