https://www.qduoj.com/problem/6/
题意是给两个字符串s,t,每次操作是在s的某个字符c后面添加一个字符d,但要求d!=c,问能不能经过某些操作后使构造出t串
贪心
几个感觉比较好的样例
aaaba
aaaaba
No
aaaba
aaabbba
Yes
baa
baa
Yes
abb
abb
Yes
cat
cacat
Yes
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<cstring>
#include<string>
#include<math.h>
#include<map>
using namespace std;
const int maxn=1e5+20;
char s[maxn],t[maxn];
int check(char *arr1,char *arr2,int l1,int r1,int l2,int r2)
{
int i,j=r2;
for(i=r1;i>=l1;i--)
{
while(j>=l2)
{
if(arr1[i]==arr2[j]&&(arr2[j+1]!=arr2[j]||(arr2[j+1]==arr2[j]&&arr1[i+1]==arr1[i])))
break;
j--;
}
if(j<l2)
break;
j--;
}
if(i==l1-1)
return 1;
return 0;
}
int main()
{
int T,i;
cin>>T;
while(T--)
{
scanf("%s",s);
scanf("%s",t);
// cout<<s<<" "<<t<<endl;
int len1=strlen(s);
int len2=strlen(t);
int flog=1;
i=0;
while(t[i]==t[0])
{
if(t[i]!=s[i])
{
flog=0;
break;
}
i++;
}
if(flog)
flog&=check(s,t,i,len1-1,i,len2-1);
if(flog)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}