题解
a为b的前缀,只需要设置两个指针即可,l1指向a中当前需要比较的字符,l2指向b中当前字符;如果a[l1]==b[l2]则 l1++,l2++ 否则 l2++。
code
#include<bits/stdc++.h> using namespace std; const int N=2e5+5;int main(){ int t; cin>>t; while (t--){int n,m; cin>>n>>m; string s,ss; cin>>s>>ss; int l1=0,l2=0; while (l1<n && l2<m){ if (s[l1]==ss[l2]){ l1++; l2++; } else l2++; } cout<<l1<<endl; } return 0; }
标签:ss,int,Prefiquence,cin,++,l2,l1 From: https://www.cnblogs.com/purple123/p/18171751