fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define GG ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  4. int main () { GG;
  5. int t; cin>>t;
  6. while(t--) {
  7. int n,m; string a,b,x="";
  8. cin>>n>>m>>a>>b;
  9.  
  10. int i=0; char c=a[0];
  11. for(int j=0;j<m;j++)
  12. { if(b[j]==c)
  13. { x+=c; i++; c=a[i];
  14. }
  15. }
  16. cout<<x.size()<<"\n";
  17. }return 0;}
Success #stdin #stdout 0.01s 5308KB
stdin
6
5 4
10011
1110
3 3
100
110
1 3
1
111
4 4
1011
1111
3 5
100
11010
3 1
100
0
stdout
2
2
1
1
3
0