水题,就扫一遍就行。只不过有点没有注意,就是在s中某个字符与t中某个字符匹配了之后,在判断完之后,t的下标要++,否则就会使“sequencee sequence”也被判为Yes。
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
char s[200005], t[200005];
// bool notbegin = false;
while (scanf("%s%s", s, t) != EOF)
{
int m = strlen(s), n = strlen(t);
int i, j;
bool flag = true;
for (i = 0, j = 0; i < m; i++)
{
for (; j < n; j++)
{
if (s[i] == t[j])
break;
}
if (j == n)
{
flag = false;
break;
}
j++;
}
// if (notbegin)
// printf("\n");
// notbegin = true;
if (flag)
printf("Yes\n");
else
printf("No\n");
}
// system("pause");
return 0;
}

本文介绍了一个简单的字符串匹配问题,并提供了一段AC代码实现。重点强调了在匹配过程中更新目标字符串索引的重要性,避免误判部分匹配情况。通过具体示例说明了如何避免常见陷阱。

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



