题目

思路
题目的意思是找出最长子列,该子列的字符必须都是字符集里面的。
对于这个问题我们先记录字符集所有出现过的元素,然后我们再逐个处理字符串的字符。如果当前字符是字符集里面的,那么cnt++,并且用一个max记录最长长度,如果cnt>max,那么max设置为cnt;如果不是里面的,那么相当于中断了,cnt设置为0。
代码
cpp
#include<stdio.h>
#include<string.h>
char str[10010],s[30];
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%s%s",str,s);
int f[26]={0};
int lenS=strlen(s);
int lenStr=strlen(str);
for(int i=0;i<lenS;i++) f[s[i]-'a']=1;
int max=0;
int cnt=0;
for(int i=0;i<lenStr;i++){
if(f[str[i]-'a']){
cnt++;
if(cnt>max) max=cnt;
}else cnt=0;
}
printf("%d\n",max);
}
return 0;
}