就是简单的查询字符串t能否由字符串s按序抽出字符组成
然后我一开始用while T了,之后我们就想乱七八糟的方法,存储每个字符在s中的下标,将t第一个字符在的下标记为last,然后在第二个字符中找s中下标大于last的,以此类推能找全就OK ,依旧T
后来队友换了for写,就A了,还是不知道while怎么就T了
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
const int maxn = 1e5 + 10;
char s[maxn], tmp[maxn];
int n;
using namespace std;
int main()
{
scanf("%s", s);
cin >> n;
int len1 = strlen(s);
for(int k=1;k<=n;++k)
{
scanf("%s", tmp);
int len2 = strlen(tmp);
int s1 = 0, s2 = 0;
for(s1 = 0; s1 < len1; s1++)
{
if(s[s1] == tmp[s2])
{
s2++;
if(s2 == len2)
break;
}
}
if(s2 == len2) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
while版本(T)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
const int N=1e5+10;
char s[N];
char t[1100];
using namespace std;
int main()
{
scanf("%s",s);
int n;
scanf("%d",&n);
int len_S=strlen(s);
for(int k=1;k<=n;++k)
{
scanf("%s",t);
int len_T=strlen(t);
//int last=0;
int i=0,j=0;
while(i<len_S&&j<len_T)
{
if(s[i]==t[j])
++j;
++i;
}
if(j==len_T) printf("YES\n");//cout<<"YES"<<endl;
else printf("NO\n");//cout<<"NO"<<endl;
}
}