CF1968B 题解
思路
首先很显然,如果
代码
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int t, n, m, now;
string a, b;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
cin >> n >> m >> a >> b;
now = 0;
for (int i = 0; i < n; ++ i) {
while (now < m && b[now] != a[i])
++ now;
if (++ now > m) {
cout << i << '\n';
goto end;
}
}
cout << n << '\n';
end:
;
}
return 0;
}