1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<string> 5 #include<algorithm> 6 #include<iostream> 7 #include<queue> 8 #include<map> 9 #include<cmath> 10 #include<set> 11 #include<stack> 12 13 using namespace std; 14 15 char dp[2505][2505]; 16 string a,b; 17 18 int main() 19 { 20 int t; 21 cin>>t; 22 while(t--) 23 { 24 memset(dp,-1,sizeof(dp)); 25 cin>>a>>b; 26 dp[0][0] = 0; 27 for(int i = 0; i <= a.length(); i++) 28 { 29 for(int j = 1; j <= b.length(); j++) 30 { 31 if(a[i-1]==b[j-1] && dp[i-1][j-1]!=-1 && i!=0) //非. * ,直接匹配 32 dp[i][j] = a[i-1]; 33 else 34 if(b[j-1]=='.' && dp[i-1][j-1]!=-1 && i!=0) //. 35 dp[i][j] = a[i-1]; 36 if(b[j-1]=='*') 37 { 38 if(dp[i-1][j-1]==a[i-1]) //重复前一个 39 dp[i][j] = a[i-1]; 40 else 41 if(dp[i-1][j]==a[i-1]) //重复当前的 42 dp[i][j] = a[i-1]; 43 else 44 if(dp[i][j-2]!=-1 || dp[i][j-1]!=-1) //匹配空串 45 dp[i][j] = 0; 46 } 47 48 } 49 } 50 if(dp[a.length()][b.length()]!=-1) 51 cout<<"yes"<<endl; 52 else 53 cout<<"no"<<endl; 54 55 } 56 return 0; 57 }