这是一个贪心+字符串匹配水题
题意:给出两个字符串s和t判断是不是可以删掉t中的部分字符其他字符顺序不变得到s
坑:区分大小写!!!!!
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
char s[100000+10],t[100000+10];
int main()
{
while(scanf("%s %s",s,t)!=EOF)
{
// for(int i = 0; i < s.size(); i++)
// {
// if(isupper(s[i]))
// s[i] = tolower(s[i]);
// }
// for(int i =0 ; i < t.size(); i++)
// {
// if(isupper(t[i]))
// t[i] = tolower(t[i]);
// }
int len = 0;
for(int i =0 ; i< strlen(t); i++)
{
if(t[i] == s[len])
{
len++;
}
}
if(len >= strlen(s))
printf("Yes\n");
else{printf("No\n");}
}
return 0;
}
从前往后匹配,匹配成功就继续往后匹配,如果·子串匹配完成就输出Yes