本质就是一个简单的贪心匹配了,在第二个串中顺着找第一个串的每个字符就可以了。
#include "stdio.h"
#include "string.h"
#include "math.h"
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAXM 1
#define MAXN 1
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b
#define Mem(a,b) memset(a,b,sizeof(a))
int Mod = 1000000007;
double pi = acos(-1.0);
double eps = 1e-6;
typedef struct{
int f,t,w,next;
}Edge;
Edge edge[MAXM];
int head[MAXN];
int kNum;
void addEdge(int f, int t, int w)
{
edge[kNum].f = f;
edge[kNum].t = t;
edge[kNum].w = w;
edge[kNum].next = head[f];
head[f] = kNum ++;
}
char s1[100005], s2[100005];
void solve()
{
int len1 = strlen(s1), len2 = strlen(s2);
for(int i = 0, j = 0; j < len2; j ++){
if( s1[i] == s2[j] ){
i ++;
if( i == len1 ){
printf("Yes\n");
return;
}
}
}
printf("No\n");
}
int main()
{
// freopen("d:\\test.txt", "r", stdin);
while( scanf("%s %s",s1, s2) != EOF ){
solve();
getchar();
}
return 0;
}